Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

[Easy] Please help what is the right replacement code

5:54 am on Aug 24, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:May 17, 2007
posts: 101
votes: 0

I have a variable, lets say $peoplename, that have dynamic output

for example




like you see, sometime there is   characther in the output, i want to replace that character in the output, please help what is looks like the right replacement code, this should be easy enough, already tried this but its looks like still not right

$nbsp =  ;
$peoplenamereplaced = str_replace($peoplename, $nbsp, $peoplenamereplaced);
6:15 am on Aug 24, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2004
votes: 0

if your special characters is only a space, you can use trim() also
9:21 am on Aug 24, 2012 (gmt 0)


WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
votes: 44

i think you are trying to do a string assignment there.

A string literal can be specified in four different ways:
http://php.net/manual/en/language.types.string.php [php.net]
5:24 pm on Aug 24, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2006
votes: 1

Hi. Try this.

$peoplename = 'Michael ';
$nbsp = ' ';
$peoplnamereplaced = preg_replace('/'.$nbsp.'/', '', $peoplename);
echo $peoplenamereplaced;

Hope this helps.
7:27 pm on Aug 24, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:June 24, 2004
votes: 1

$nbsp = ' ';
$peoplenamereplaced = str_replace($nbsp, '', $peoplenamereplace);

-- Roger

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members