Maybe I'm not looking the right way, but I'm not finding what I need through search so could I get a bit of help please? I have a line of code that replaces anything that is not a letter or number with "-" $text = ereg_replace('[^A-Za-z0-9]', '-', $text); Code (markup): But I also need to add in the "~" character to the list of ones not replaced. How do I do that? I tried these $text = ereg_replace('[^A-Za-z0-9~]', '-', $text); $text = ereg_replace('[^A-Za-z0-9\~]', '-', $text); $text = ereg_replace('[^A-Za-z0-9/~]', '-', $text); Code (markup): But every one of them still replaced the "~" with a "-". So obviously I'm missing something, probably pretty basic knowing me lol. Thanks!
$text = ereg_replace('|[^A-Za-z0-9~]|', '-', $text); Code (markup): Just returns a whole bunch of errors to me. Any other ideas? Thanks!
Hmmmm $text = preg_replace('|[^A-Za-z0-9~]|', '-', $text); Code (markup): goes back to replacing the "~" with a "-". Also tried $text = preg_replace('[^A-Za-z0-9~]', '-', $text); $text = preg_replace('[^A-Za-z0-9\~]', '-', $text); $text = preg_replace('[^A-Za-z0-9/~]', '-', $text); $text = preg_replace('|[^A-Za-z0-9\~]|', '-', $text); $text = preg_replace('|[^A-Za-z0-9/~]|', '-', $text); Code (markup): and they do too. Any other suggestions? Thanks for the help!
I gave it a try danx10, it does the same thing. Guess I'm gonna be stuck with it the way it is. Thanks anyways everybody.
Mine should work as it would replace all a-zA-Z0-9 with - (and NOT replace the ~ character) Which is what your description suggests you wanted?
Ummmm not quite lol. Sorry if I didn't explain it clearer. I need to replace any character that is NOT in the set (a-z, A-Z, 0-9, ~) with a "-". Right now it replaces anything that is not in the set (a-z, A-Z, 0-9) but I'm looking to add "~" to that set of characters not being replaced. For example, if you feed "~All cats are furry-usually~" into it, right now it spits out "-All-cats-are-furry-usually-" and I'm looking to make it spit out "~All-cats-are-furry-usually~" instead. Thanks!
Hey, providing I actually understood what you're after (seems straight forward) this will do it! $content = preg_replace('/[^a-zA-Z0-9~]/', '-', $content); Code (markup): Let me know if that helps ya!