-1

Is it possible to change a concatened string, with a variable in the string?

  $x = 'XXX' . $y;

Is there a way to have $x contain 'XXY', without changing this?

What do I need to set in $y for this? Does there exist something like a "remove previous character"?

EDIT:

Maybe i didnt made myself crystal clear:

$y needs to be a string, no functions or anything. Its due to discover an exploit...

Michael Leiss
  • 5,276
  • 3
  • 19
  • 25

4 Answers4

1
$x = substr("XXX", 0, -1) . $y;

In light of your edit, I don't think you can do what you want the way you want it to happen.

Matías Cánepa
  • 5,406
  • 4
  • 53
  • 92
1

Not that I know of, but you can use substr_replace:

$x = substr_replace($x, $y, -1);

If you want to replace the exact number of characters in $y at the end of $x:

$x = substr_replace($x, $y, -(strlen($y));
sjagr
  • 15,254
  • 4
  • 38
  • 65
0

Just set the value of $y to a backspace character plus 'Y':

$y = chr(8) . 'Y';
littleibex
  • 1,590
  • 2
  • 13
  • 34
-1

Try this:

$y = chr(8).'Y';
$x = 'XXX' . $y;

chr(8) should give you a backspace character.

Headshota
  • 20,343
  • 11
  • 58
  • 79