I’m new to PHP and trying to customize the following PHP line on my Joomla site:
<? if ($event->venue_id) : ?><?=@service('com://site/component.model.venues')->id($event->component_venue_id)->getItem()->title?><? endif ?>
The line outputs the address, but I want to shorten the outputted address by removing the city and country. Is this possible some how in PHP?
I have been trying to do it with ‘preg_replace’ but not having much success. All the addresses are UK address so I tried:
<? if ($event->venue_id) : ?><?=@service('com://site/component.model.venues')->id($event->component_venue_id)->getItem(preg_replace('UK','',($event->venue_id))->title?><? endif ?>
Thanks for any help!
If you just want to remove the
, UKpart, you don’t need preg_replace, you can just do a regular str_replace:Change this:
To this:
This will replace
, UKwith an empty string. So it will turn an address like this:Into this:
If you also want to remove, for example, the string
London,, you can just add another str_replace:This would result in that address becoming: