Underdog
Underdog

Reputation: 129

ignore the characters contained in the database value in php

For example, I have a database table as follows :

enter image description here

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

Answers (3)

Duane Lortie
Duane Lortie

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

Nick
Nick

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

Jees K Denny
Jees K Denny

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

Related Questions