-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,395
  • 3
  • 21
  • 27

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,770
  • 4
  • 57
  • 97
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,983
  • 5
  • 40
  • 67
0

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

$y = chr(8) . 'Y';
littleibex
  • 1,705
  • 2
  • 14
  • 35
-1

Try this:

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

chr(8) should give you a backspace character.

Headshota
  • 21,021
  • 11
  • 61
  • 82