Page 1 of 1

ereg_replace

Posted: Tue Aug 02, 2005 8:22 am
by gurjit
hi all,

how do i replace spaces or any text other than a-z using ereg_replace

for example

if i had the text "hello there." and i wanted to take out spaces and the dot how would i do that?

i tried this and it never worked

Code: Select all

<?php

$chosen_locationname = (ereg_replace(" [space]*_.-", "", "hello there."));
?>
i wanted the output to be:
"hellothere"

Posted: Tue Aug 02, 2005 10:30 am
by anjanesh
If replacing is all you want to do then

Code: Select all

$str = "Hello There."
$str = str_replace(array(' ','.'),"",$str);

Posted: Tue Aug 02, 2005 11:46 am
by gurjit
but the string could have anything inside it.

i want to only have a-z characters and all spaces trimed, so there are no spaces.

Posted: Tue Aug 02, 2005 11:49 am
by nielsene

Code: Select all

$str = "Hello There."
$str = ereg_replace("[^A-Za-z]","",$str);