Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty Templates PHP - Remove specific text from a string

Tags:

php

smarty

I have the following code:

{$product.name}

This outputs all of our products, unfortunatly they are stored in the database as 'CompanyNameProductName'.

I want to remove the string 'CompanyName' from the string $product.name

How can I do this in PHP?

like image 702
CLiown Avatar asked Jul 24 '26 15:07

CLiown


1 Answers

Replace

{$product.name}

by

{$product.name|replace:'CompanyName':''|capitalize}

This way you can do it in your Smarty template without having to modify your PHP.

like image 63
JochenJung Avatar answered Jul 26 '26 07:07

JochenJung