5

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!

1
  • 1
    Why don't you use str_replace Commented Jul 21, 2016 at 10:32

4 Answers 4

10

Instead of preg_replace() use str_replace() like below:-

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

so the code will be:-

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

Output:- https://3v4l.org/NTrFJ

Sign up to request clarification or add additional context in comments.

Comments

3

Use str_replace() Function

str_replace("SRL","",$title);

Comments

2
 $title = "SOMETHING SRL";
 $title = trim(str_replace("SRL","",$title));

Use this code

Comments

0

You can use str_replace() with trim().

The str_replace() function replaces some characters with some other characters in a string.

str_replace(find,replace,string,count) 

Note: String Parameter is Required. Specifies the string to be searched and count is optional

Use like this

 $stringReplace = "Hello World";
 $stringReplace = trim(str_replace("world","Programmer","Hello world!"));

Output

Hello Programmer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.