0

I am trying to replace first 2000 characters of a string with null.

For example:

$content = "nvinveneuifnoimmio";
$my_result = "fnoimmio";

I mean that I want the first 10 characters to be removed or to be replaced with a space character in above example.

whats the easiest way to do it?

thanks

Kostas Mitsarakis
  • 4,772
  • 3
  • 23
  • 37

2 Answers2

0

substr is what you need. It will take a section of the given string, x characters from the start.

$content = "nvinveneuifnoimmio";
$my_result = substr($content, 10);

If you want to replace instead, you can use a combination of substr_replace and maybe str_repeat:

$content = "nvinveneuifnoimmio";
$characters = 10;
$my_result = substr_replace($content, str_repeat(' ', $characters), 0, $characters);
rjdown
  • 9,162
  • 3
  • 32
  • 45
0

Use substr()

$my_result = ' ' . substr($content, 10);
Tony DeStefano
  • 819
  • 6
  • 11