|
Posted by ZeldorBlat on 05/05/07 18:40
On May 4, 3:10 pm, misiek <michal_augustyn...@gazeta.pl> wrote:
> ZeldorBlat wrote:
> > On May 4, 10:43 am, misiek <michal_augustyn...@gazeta.pl> wrote:
> >> Hi
>
> >> Problem to use
>
> >> Works for all characters but not for - (dash).
>
> >> when I use
> >> eregi('[\=\+\-\]', 'te-xt')
>
> >> return null
>
> >> when I use
> >> eregi('[\=\+\-]', 'te-xt')
>
> >> return true
>
> >> when I use
> >> eregi('[\-\+\=\]', 'te-xt')
>
> >> return null
>
> >> Why its happening ?
>
> >> Thanks for help
>
> >> Basicly what I need todo is check in string if there is character to
> >> repalce then replace
>
> >> I was trying in preg_match and preg_replace but wired not working.....
>
> >> This is sample how I need todo..
>
> >> $characters = array['&',''','/','_','-']; in this array I need to store
>
> >> this characters & ' / _ - ( not sure how to put single quote and
> >> a slash)
>
> >> foreach($characters as $character)
> >> {
> >> $pattern .= '\\'.$character;}
>
> >> $pattern .= '\\';
>
> >> if (eregi($pattern, $string))
> >> {
> >> eregi_replace($pattern, '', $string)
> >> }
>
> >> thanks for help guys
>
> > So you want to remove certain characters from a string? I've said it
> > before and I'll say it again: why do people insist upon using regular
> > expressions to do things that str_* functions can handle in a much
> > easier and faster way? Not only will it run faster, but you'll save
> > yourself from exactly the kind of headaches you're experiencing.
>
> > $chars = array('&', "'", '/', '_', '-');
> > $output = str_replace($chars, '', $string);
>
> Ups sorry for my language.
> I just said, that this would work out. But what about if statement.
> First I need to check if there is a character in the string then remove it
I don't understand why you would need to check for the character
before removing it. If it's there, you want to remove it, and, if it
isn't, you don't want to do anything. So, if you try to remove and it
isn't there, nothing will happen anyway.
Navigation:
[Reply to this message]
|