hi I have a little doubt I would like to replace a string by 0
$cadena = '1234567'
hi I have a little doubt I would like to replace a string by 0
$cadena = '1234567'
You can use the str_repeat
function that repeats a string n
times, in this case the number of characters that%% of%
$cadena = str_repeat( "0" , strlen($cadena) )
You can use the preg_replace function with a regular expression that replaces each numeric character with a% % co:
$cadena = '1234567';
$cadena0 = preg_replace('/\d/', '0', $cadena);
Here you have a link from Ideone .
$cadena = '1234567'
str_replace('1234567','0000000',$cadena);
Note: This way you can replace the substring '1234567' with '0000000' in any other string other than '1234567' as well (for example 'qqs1234567acv').