Re: String Manipulation
| From: | Bas Jobsen | Date: | Thu, 25 Jul 2002 15:33:52 +0000 |
| Subject: | Re: String Manipulation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109514@lists.php.net to get a copy of this message | ||
Maybe something like:
eregi('([a-z]*)( *)(\(*)([a-z]+)( *)(\)*)([a-z]*)',$string,$matches);
echo $matches[4];
Op donderdag 25 juli 2002 17:13, schreef Mike:
> 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