Reputation: 269
I have a set of page soure code that has elements such as
<p class='style1'>
, <p class=3DMsoNormal>
, <span style=3D'font-size:12.0pt'>
, <p class=3DMsoNormal>
but i want am trying to replace the all single quotes with double quotes in the all of the source code and those that dont have quotes to receive double quotes such as
<p class=3DMsoNormal
and remove the text '3D' from all those that have it.
Below are a series of functions i tried that didn't work. Can someone help me find a solution to this? Thanks
<?php
// test files holds the source code
$html_part = file_get_contents('testRegex.html');
$cSeq = "/(.*)='(.*)'/"; //code sequence
$nSeq = "/(.*)="."(.*)"."/"; //new sequence
preg_match_all($cSeq, $html_part, $matches);
preg_replace($cSeq, $nSeq, $html_part);
echo $html_part;
?>
Upvotes: 0
Views: 214
Reputation: 151730
You might want to take a look at quoted_printable_decode()
instead of removing the '3D' manually.
Upvotes: 0
Reputation: 3620
I'm not sure this regex's are the way to go.
Maybe consider using a parser to read in the file, and write it back out / prettify it.
I've used Beautiful Soup in the past.
Upvotes: 1
Reputation: 1866
preg_replace("/(.*)?='(.*)?'/","\\1=\"\\2\"",$str)
you need to use backreference http://www.regular-expressions.info/brackets.html
Upvotes: 0