I have the below simple replace working
<?php
$mydata= '15-2003';
$pattern = '/[-]/';
$replacement = ' ';
echo preg_replace($pattern, $replacement, $mydata);
?>
Which outputs 15 2003
However when I put it in my foreach loop it doesn't seem to work?
I have this
<?php foreach ($tests as $test): ?>
<tr>
<?php
$mydata= htmlout($test['f']);
$pattern = '/[-]/';
$replacement = '';
echo preg_replace($pattern, $replacement, $mydata);
?>
<?php endforeach; ?>
Which outputs 15-2003 Where am I going wrong here?
htmlout is the below custom function.
<?php
function html($text)
{
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
function htmlout($text)
{
echo html($text);
}
When I do var_dump($mydata); I get NULL
str_replace()will do the job just fine. I also note that in your looping example you are replacing with an empty string instead of a space like your first example.str_replacehere, right?htmloutand what does it return? (if this is converting to unicode you may not be replacing the same hyphen you think you are...)str_replace, which is faster. Can you do a simplevar_dump($mydata);?