okay... the break down

the regexp: '(.*(\(|\[)|(\)|\]).*)'
.* = any character from zero to infinite number of times
(\(|\[) = either ( or [ (they are escaped with a "\" bcz they have other
meaning
then I have another pipe "|" meaning "or"
(\)|\]) = either ) or ]
.* = again... any char any # of times
if you want only the parenthesis or the brackets removed just leave out the
".*" in the regexp.

the ${$data}was only there in my example working code bcz I had 6 vars named
$string1 through $string6. I wanted to call each of them in a loop but you
can't say $string$i. I said $data = "string" . $i., which would translate to
just a string like this "string1". I could have just used $$data, which is
the same as saying $string1 but I hate to use the double "$$" because it
looks bad. Sorry if I threw you off. You can just do it like this:

$text_out = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', $text_in);


Jim Grill
Support
Web-1 Hosting
http://www.web-1hosting.net
----- Original Message -----
From: "Mike" <[EMAIL PROTECTED]>
To: "'Tech Support'" <[EMAIL PROTECTED]>; "PHP List"
<[EMAIL PROTECTED]>
Sent: Thursday, July 25, 2002 10:48 AM
Subject: RE: [PHP] String Manipulation


> Ok, It works and everything, but I just was wondering:
> $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data});
> --------------------------------------------------^      ^
> what does this do exactly, I see that you are replacing all the
> characters [] and () but what is the ${$data} for?
> Also for future reference is there a way that you could return the
> string with all the parentheses stripped out?
> Thank You again,
> Mike
> [EMAIL PROTECTED]
>
>
> And what would be
> -----Original Message-----
> From: Tech Support [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, July 25, 2002 11:39 AM
> To: Mike; PHP List
> Subject: Re: [PHP] String Manipulation
>
> I tested this out with success.
> $string = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', $string);
>
> ###################
> // Here is actual working code
> $string1 = "(Something) - is wrong with me";
> $string2 = "something - (is wrong with me)";
> $string3 = "something - (is wrong with me";
> $string4 = "[something] - is wrong with me";
> $string5 = "something - [is wrong with me]";
> $string6 = "something - [is wrong with me";
> for ($i = 1; $i < 7; $i++)
> {
>  $data = "string" . $i;
>  $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data}); // the
> magic
> line. feed it the string(s).
>  print "<b>$i)</b> $data<br>";
> }
> ###################
>
> Jim Grill
> Support
> Web-1 Hosting
> http://www.web-1hosting.net
> ----- Original Message -----
> From: "Mike" <[EMAIL PROTECTED]>
> To: "PHP List" <[EMAIL PROTECTED]>
> Sent: Thursday, July 25, 2002 10:13 AM
> Subject: [PHP] String Manipulation
>
>
> > Hello all,
> > I know that this has probably been discussed before and that you will
> > tell me to go through all the back messages on the list but I really
> > don't have time to do that because I am on a really tight schedule,
> but
> > I was wondering if anyone could give me some pointers on how to pull
> > some information out of a string. I have something like this:
> > (Something) - is wrong with me
> > or
> > something - (is wrong with me)
> > or
> > something - (is wrong with me
> >
> > what I need to know how to do is take the stuff that is inside the
> > Brackets (or partial brackets) and put them into another string
> > the way I am currently doing it is like this:
> > Variable names have been changed per my boss(My Boss wanted me to
> change
> > them for some reason)
> > <?
> > $parenpos = strpos($tartist,")");
> > $bracketpos = strpos($tartist,"]");
> > if($parenpos){
> > $artist = trim(substr($tartist,0,$parenpos));
> > $title  = trim(substr($tartist,$parenpos+3));
> > $secondparenpos = strpos($title,"(");
> > $secondbracketpos = strpos($tartist,"[");
> > $title = trim(substr($title,0,$secondparenpos));
> > }elseif($bracketpos){
> > $artist = chop(substr($tartist,1,$bracketpos-1));
> > $title  = trim(substr($tartist,$bracketpos+3));
> > }
> > ?>
> >
> > I know that there has to be a shorter version of this, can anyone help
> > me out with it?
> >
> > Thank You,
> > Mike
> > [EMAIL PROTECTED]
> > [EMAIL PROTECTED]
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>



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

Reply via email to