Peate
Peate

Reputation: 11

PHP Filter a specific word

My output from the mysql database looks like this: icon-search icon-white (from bootstrap framework)

And now I want, that it only displays icon-search without the icon-white string.

How can I do that?

Thanks

Upvotes: 1

Views: 152

Answers (3)

FabianoLothor
FabianoLothor

Reputation: 2977

If you no longer need the text icon-white, just update the values in database:

UPDATE you_table SET you_column = REPLACE(you_column, ' icon-white', '') WHERE you_conditional;

This will increase the performance of your application, but if you still need the text, then use the solution of Edd.

Upvotes: 1

Edd
Edd

Reputation: 683

If $var contains icon-search icon white, try it this way:

$var = str_replace(' icon-white', '', $var);

Upvotes: 4

Lee
Lee

Reputation: 10603

echo str_replace("icon-white", "", $your_output);

Or for the sake of being a little more pedantic on what icon-white strings to remove something like this would work too

echo preg_replace("/(class=[\'\"].*?)(\s*icon\-white\s*)(.*?[\'\"])/i", "\\1\\3", $your_output);

Upvotes: 1

Related Questions