View Full Version : Simple php problem
xiaodao
03-04-2006, 04:28 AM
Hi
like i have "web design" string
how can i get rid of the spacing between "web design" and make it "webdesign"? or how can i get first two letters of the "web" and then "design" to make it like "wedesign"?
lansing
03-04-2006, 04:51 AM
I don't think I missed anything...so can you say that again?
xiaodao
03-04-2006, 04:52 AM
well "web design" is a string with a spacing between web and design
so how can i get rid of the spacing to make the string "webdesign"
arnyinc
03-04-2006, 09:45 AM
http://us2.php.net/manual/en/function.str-replace.php
ns1987
03-04-2006, 12:19 PM
You could use str_replace(), or substr() and stristr() or strchr() .
Look the functions up on PHP.net for usage.
Simple code to replace all spaces in a word:
str_replace(' ', '', $string);
To get all of the words in a string and put them into an array:
$words = explode(' ', $string);
You can then just get the first two of the first word using:
$new_string = substr($words[0], 0, 2) . $words[1]);
You can also write a foreach loop to handle more than two words.
Hope that helped.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.