|
Posted by misiek on 05/04/07 19:10
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
Navigation:
[Reply to this message]
|