I know it is not recommended to parse XML / HTML with a reg-ex, but i am trying to do this simple thing:
<?php
echo phpversion()."<br><br>";
$test_1 = '<Tag attr="attr_value">Tag_value</Tag>';
$test_2 = $test_1.str_repeat(' ',1000);
$test_3 = $test_1.str_repeat(' ',2000);
$match = '!<(.*?) (.*?)="(.*?)">!';
$replace = '<\\2>\\3</\\2><\\1>';
$output_1 = preg_replace($match, $replace, $test_1);
$output_2 = preg_replace($match, $replace, $test_2);
$output_3 = preg_replace($match, $replace, $test_3);
echo "xml: ".htmlspecialchars($test_1)."<br>";
echo "1: ".htmlspecialchars($output_1)."<br>";
echo "2: ".htmlspecialchars($output_2)."<br>";
echo "3: ".htmlspecialchars($output_3)."<br>";
?>
I mean, putting an attribute and its value out of the container tag. All working fine with test_1 and test_2 examples, but if I add more spaces like in test_3, the return string is empty. Can someone try this code?
In this example it works adding 1411 spaces. One more (1412) and doesn't ...
I have tested on 5.3.8 and 5.3.19 PHP versions.
Thanks.