I'm trying to parse a query string and have run into something I can't quite figure out.
Trying to match a string that can contain either < or >, but I'm seeing some weird output only when the string contains a <.
Example:
<?php
$gt = 'wt>f';
preg_match_all("/([A-Za-z<>]+)/", $gt, $gtmatches);
?>
<pre><?php print_r($gtmatches); ?></pre>
Returns as expected:
Array
(
[0] => Array
(
[0] => wt>f
)
[1] => Array
(
[0] => wt>f
)
)
But simply replacing that > with a <, gives really weird output:
Code:
<?php
$lt = 'wt<f';
preg_match_all("/([A-Za-z<>]+)/", $lt, $ltmatches);
?>
<pre><?php print_r($ltmatches); ?></pre>
Outputs:
Array
(
[0] => Array
(
[0] => wt Array
(
[0] => wt
I've tested this on PHP 5.6.24/IIS 10, and locally on PHP 5.6.32/Apache 2.4.29.
Solved thanks to iainn (damn you guys are fast!)
My browser was interpreting the < as the start of a tag, looking at the source, everything is fine.