I used one solution to fix one problem, then when I went to fix another problem, it made the other problem occur again.
I’m currently using this to replace spaces with dashes.
$var2 = str_replace(' ', '-', $var2);
Now say $var2 is an address, so 5019 Hill Street. I had it set to add a %20 to numerals so that it would say it as 5 0 1 9. When I put the str_replace to add the dash, it screwed this up.
Is there a way to put within the string replace, both functions? I was using this to add the space between numerals.
if(is_numeric($var2)){
$var2 = addSpaceToStr($var2);
}
function addSpaceToStr($str){
$strLen = strlen($str);
$strWithSpace = '';
for($i = 0; $i <$strLen; $i++){
$strWithSpace .= $str[$i];
if(($i+1) != $strLen){
$strWithSpace .= '%20';
}
}
return $strWithSpace;
}
These are in two different files, so I tried different variations of putting them in just one file without success. As well as keeping them in separate files without success either. The first file curls over the variable with the dashes added, then the second file is suppose to add spaces to the numbers, but now it’s not adding the spaces to the numbers. Any ideas?
Thanks!
I fixed this issue by adding this,
$var2 = preg_replace("/(\d)/", '$1 ', $var2);$var2 = str_replace(' ', '-', $var2);