Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove specific string from string input in PHP

Tags:

php

wordpress

I have an string from title, and i want to remove specific character/string from this. Title is show with bloginfo('sitename').

I try to made something like that:

<?php
   $title = preg_replace('/'. preg_quote('SRL', '/') . '$/', '', bloginfo('sitename'));
   print $title;
?>

...but don't work.

The title input is: SOMETHING SRL, and i want to show just "SOMETHING".

Thanks for help!

like image 465
Diaconu Eduard Avatar asked Dec 15 '22 04:12

Diaconu Eduard


1 Answers

As i first commented, instead of preg_replace() use str_replace() like below:-

echo trim(str_replace('SRL','',$title)); // first replace `SRL` and then remove extra spaces

so code will be:-

<?php
   $title = trim(str_replace('SRL','',$title));
   print $title;
?>

Output:- https://eval.in/609265

like image 66
Anant Kumar Singh Avatar answered Dec 25 '22 11:12

Anant Kumar Singh