RE: [PHP] String Manipulation
| From: | Mike | Date: | Thu, 25 Jul 2002 15:48:43 +0000 |
| Subject: | RE: [PHP] String Manipulation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109521@lists.php.net to get a copy of this message | ||
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
Funyon@funyon.com
And what would be
-----Original Message-----
From: Tech Support [mailto:jgrill@web-1hosting.net]
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" <funyon@funyon.com>
To: "PHP List" <php-general@lists.php.net>
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
> funyon@funyon.com
> mmacrae@wwnet.net
>
>
> --
> 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