帮我写一些字符串到“php语法”

I am having some trouble on writing some strings I want to use in PHP syntax with preg_match_all.

All I managed to do correctly is to write <span style=""> to $regex_pattern = "/\<span style=\"color: red;\"\>(.*?)\<\/span\>/i"; but can't do any further than that.

I mean I cant write correctly <h3 class=''> or get the link between <h3 class=""><a href=" and </a>. Please help me with the above and give me some examples if you want or any online tools for this.

Thanks in advance!

echo "<span style='color:red;'>Text</span>";

Best way is to:

if(condition){

?>

<!-- HTML here -->

<?

}

else


  linefeed (LF or 0x0A (10) in ASCII)
  carriage return (CR or 0x0D (13) in ASCII)
\t  horizontal tab (HT or 0x09 (9) in ASCII)
\\  backslash
\$  dollar sign
\"  double-quote
\[0-7]{1,3}     the sequence of characters matching the regular expression is a character in octal notation
\x[0-9A-Fa-f]{1,2}  the sequence of characters matching the regular expression is a character in hexadecimal notation

Please consider the communities advice when we say 'Do not parse html with regex'.

Instead you should look into parsing it with the DOMDocument module compiled into most builds of PHP.

There is a tutorial I like on phppro.org which seems to be down right now.

So heres a link to Google webcache for the page. Also here is the documentation to DOMDocument.

There is a pretty steep learning curve to DOMDocument but it makes your code infinitely more manageable then regex.