I’m trying to remove currency symbols from a string, but getting an ‘undefined variable’ error. Sorry if this is totally dumb, I’m a newbie!
<? if ($event->ticket_cost) : ?>
<? $cost = $event->ticket_cost ?>
<? $cost = preg_replace("€£$","", $cost) ?>
<?=$cost ?>
<? else : ?>
<? echo '' ?>
<? endif ?>
Thanks!
You need to use delimitters:
Also since
$is special character in regex, you need to escape it with backslash like above.Also you are using
<?, it should be<?=or better<?phpunless you are not using any other specialized setting or stuff.