Page 1 of 1

replace whitespace with a hyphen

Posted: Thu Feb 08, 2007 6:38 am
by ianhull
Hi Guys,

I am wondoering how to replace whitespace with a dynamic striing to a hyphen(-)

For example, the end user might type, Red Curtains,

I need to translate this into red-curtains.html

please help.

Thanks

Posted: Thu Feb 08, 2007 6:40 am
by volka
You want to manipulate string, take a look at the string functions of php at http://de3.php.net/manual/en/ref.strings.php

Posted: Thu Feb 08, 2007 6:50 am
by ianhull
Thanks Volka,

I am still a bit confused though, as I never know what position the white space will be in.

Any help or examples would be vey much appreciated.
Thanks

Posted: Thu Feb 08, 2007 6:52 am
by mickd
More specifically you can look into str_replace from volka's link.

Also, if you need, strtolower or not, here it is just incase.

Posted: Thu Feb 08, 2007 6:55 am
by ianhull

Code: Select all


<?php
$string = "Red Curtains";
$newstring = str_replace(" ", "-", $string );
echo $newstring;
?>

This does the job

Posted: Thu Feb 08, 2007 6:57 am
by ianhull
Yes thanks mickd

I did need to convert to lower case too :)

Thanks guys