Welcome to WebmasterWorld Guest from 54.224.160.42

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Scan string for first (

     
12:00 pm on Apr 5, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 15, 2004
posts:192
votes: 0


Hi,

Can someone tell me the best/fastest way to extract data from a given position.

I have a string...

$string = "My Name (PumpkinHead)";

I need to pull out...

$extract = "(PumpkinHead)";

So really, I need to scan for the first ( then subtract one character position and extract everything after.

Hope that makes sense! Thanks in advance.

12:46 pm on Apr 5, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 1, 2004
posts:607
votes: 0


Regular expressions are what you need - they work like this:


$string = "My Name (PumpkinHead)";
$string =~ /(\(.+?\))/;
$extract = $1;
1:11 pm on Apr 5, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 15, 2004
posts:192
votes: 0


Sorry I thought I posted this in the php section. Has it been moved?
1:14 pm on Apr 5, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 15, 2004
posts:192
votes: 0


Nevermind, I found it!

strpos