Page 1 of 1

preg_match() returning xml type tags....

Posted: Sat Sep 23, 2006 8:41 pm
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?

Posted: Sat Sep 23, 2006 9:37 pm
by feyd
Care to post your pattern?

Posted: Sun Sep 24, 2006 11:30 am
by Burrito

Code: Select all

preg_match('/the-link-url(.*?)\s+/i',$string,$matches);

Posted: Sun Sep 24, 2006 12:27 pm
by feyd
Okay, so that's not going to help much.. what about $string?

Posted: Sun Sep 24, 2006 12:32 pm
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";

Posted: Sun Sep 24, 2006 1:05 pm
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

Posted: Sun Sep 24, 2006 1:32 pm
by Burrito
weirdness...have you ever seen or heard of this before?

Posted: Sun Sep 24, 2006 1:42 pm
by feyd
Doesn't sound familiar in the slightest.

Posted: Sun Sep 24, 2006 2:57 pm
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