PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 8, 2022

[FIXED] Remove specific string from string input in PHP

 January 08, 2022     php, wordpress     No comments   

Issue

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!


Solution

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



Answered By - Anant Kumar Singh
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing