Reputation: 129
For example, I have a database table as follows :
I want to show lname value in html but by eliminating the " Mr. " without changing the values contained in the database . is there any way to do this using a php script ?
Upvotes: 2
Views: 51
Reputation: 1260
Just to show there are more ways to skin a cat...
$name = "Mr. Smith";
$user = strstr($name, 'Mr. ', true); // As of PHP 5.3.0
echo $user; // prints Smith
Upvotes: 1
Reputation: 10143
Use preg_replace():
echo preg_replace('/(mr\.\s+|ms.\s+)(.*)/ui', '$2', 'Mr. Bean');
// Mr. Bean -> Bean
// Bean -> Bean
// Ms. Stone -> Stone
// Jack Bean -> Jack Bean
Upvotes: 5
Reputation: 527
You can Do it with the Explode Function.Try it Below Code. $name= "place your lname"
<?php
$name = "Mr. Smith";
$split = explode(" ", $name);
echo $split[1];
?>
Upvotes: 1