ereg_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

ereg_replace

Post 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"
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

If replacing is all you want to do then

Code: Select all

$str = "Hello There."
$str = str_replace(array(' ','.'),"",$str);
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Code: Select all

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