preg_match() returning xml type tags....

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

preg_match() returning xml type tags....

Post by Burrito »

I just came across this this evening and it seemed very odd to me.

I'm using a preg_match() to find a value within my string...simple enough. But when I echo out my $matches[1] key (or even print_r() the entire array for that matter) it's adding on '</key><string>my matched string is in here</string>'

the xml type tags are what it's adding (</key>, <string>, and </string>).

has anyone ever seen this? or more importantly, does anyone know a way to avoid this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Care to post your pattern?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Code: Select all

preg_match('/the-link-url(.*?)\s+/i',$string,$matches);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Okay, so that's not going to help much.. what about $string?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

this is a sample (I've changed the domain, but that's it)

Code: Select all

$string = "&&2bf4d *&36424 pasthro the-link-urlhttp://ap.somedomain.com?ar=344cEFG42&al=ERRc34433 &&2cf5d *&3srr2f4";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Works fine for me. :?

Code: Select all

[feyd@home]>php -r "$string = '&&2bf4d *&36424 pasthro the-link-urlhttp://ap.somedomain.com?ar=344cEFG42&al=ERRc34433 &&2cf5d *&3srr2f4'; preg_match('/the-link-url(.*?)\s+/i',$string,$matches); var_dump($matches);"
array(2) {
  [0]=>
  string(63) "the-link-urlhttp://ap.somedomain.com?ar=344cEFG42&al=ERRc34433 "
  [1]=>
  string(50) "http://ap.somedomain.com?ar=344cEFG42&al=ERRc34433"
}

[feyd@home]>php -v
PHP 5.1.5 (cli) (built: Aug 15 2006 23:54:56)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
    with Xdebug v2.0.0beta6, Copyright (c) 2002, 2003, 2004, 2005, 2006, by Derick Rethans
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

weirdness...have you ever seen or heard of this before?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Doesn't sound familiar in the slightest.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

well damn,

I hate to have to run it through a str_replace() after I'm found my match, but there's no other way to get rid these extra 'tags' 8O
Post Reply