regex – I am trying to extract <xs:element name="xyz"> strings from an XML file using PHP. But I get no matches in preg_match_all(). How do I get around this?-ThrowExceptions

Exception or error:

I have tried my regular expression on and it works. Cannot seem to figure out why it doesn’t work inside my code.

XML file – schema.xsd:

Complete Code (line 27 to 47):

Code in a separate file:

$re = '/<xs:element\sname=\"[a-zA-Z]+\">/';

$filename = "schema.xsd";
$str = file_get_contents($filename);

//echo htmlentities($str);

echo $str;

echo preg_match_all($re, $str, $matches);

// Print the entire match result
echo "<br><br>";
echo "<br>";
echo htmlentities($matches[0][1]);
echo "<br>";
echo htmlentities($matches[0][2]);
echo "<br><br>";

$string = "";

echo "type of dollarstring :" . gettype($string);

/*foreach($matches as $match)

$string = implode ($matches);

$file = fopen("test.sql", "w") or die("Unable to open file!");
fwrite($file, $string);
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *