Home > Archive > PHP Language > May 2004 > Daft ereg_replace() question.....
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Daft ereg_replace() question.....
|
|
| Bonge Boo! 2004-05-12, 7:21 pm |
| I thought this would be easy, but have wasted the best part of 2 hrs trying
to make it work
I have a string:
$string = "!!shocking.jpg";
I want to strip of the !! and replace with a single underscore. I'd like to
do that at any position in the string.
I know that ereg_repalce or preg_replace will do this, but I can't make it
work. If I use the following GREP syntax in Bbedit (Mac text editing
programming) it would work
preg_replace( '[\!]+' , '' , $string );
So I'm guessing that preg_ and ereg_ escape characters must be different? Or
is there something special about ! ?
| |
| Janwillem Borleffs 2004-05-12, 7:21 pm |
| Bonge Boo! wrote:
> So I'm guessing that preg_ and ereg_ escape characters must be
> different? Or is there something special about ! ?
You are thinking to difficult here, the following should be sufficient:
$bla = '!!en!!dat!!';
print preg_replace("/!+/", "_", $bla);
JW
| |
| Bonge Boo! 2004-05-14, 6:30 am |
| On 9/5/04 1:22, in article 409d79e0$0$65933$a344fe98@news.wanadoo.nl,
"Janwillem Borleffs" <jw@jwscripts.com> wrote:
>
> You are thinking to difficult here, the following should be sufficient:
>
> $bla = '!!en!!dat!!';
> print preg_replace("/!+/", "_", $bla);
Damn. I'm an idiot. I had:
preg_replace( $preg_replace , " " , $photos_uploaded_clean );
Thinking that would then replace the value of $photos_uploaded_clean with
the preg_replace function, and hence would be able to:
print $photos_uploaded_clean; and see the result.
But I guess that would only happen is I had:
$photos_uploaded_clean = preg_replace( $preg_replace , " " ,
$photos_uploaded_clean );
|
|
|
|
|