Re: ereg_replace help wanted

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 29 Sep 2004 George Pitcher wrote:

> The problem is that I think that some of my users are pasting the range in,
> rather than re-typing (I don't really want to stop them from pasting) and I
> am sure that sometimes the '-' is coming over as something other than a
> conventional hyphen.
> 
> Can anyone suggest a filter that will handle my hyphens correctly,
> regardless of what type of hyphen the user is entering?

You probably don't need ereg_replace (though if I did, I'd actually use 
preg_replace), you can probably do it more simply with str_replace.  
But first you have to know what characters you're actually getting.  
Say they are '*', '_', and '~' (just an example), then you can do it 
easily with:

	$newstring = str_replace(array('*', '_', '~'), array('-', '-', '-'), 
$string);

Or with:

	$newstring = preg_replace('/[*_~]/', '-', $string);

Another approach would be to replace all non-alphanumeric characters 
(other than commas) with a '-', then you are treating all punctuation 
characters as dashes:

	$newstring = preg_replace('/[^a-zA-Z0-9,]/', '-', $string);

But that might be overkill ...

--
Tom

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux