regex - What is differerent between using $subject and substr($subject,3) in example preg_match() in php.net -


I have read how the preg_match function is used, I do not know how $ subject and substrate What is the difference between using, 3) preg_match ($ pattern, $ theme, $ matches, PREG_OFFSET_CAPTURE, 3) and preg_match ($ patterns, substr ($ theme, 3), $ matches, PREG_OFFSET_CAPTURE). Please help me understand and check below the function why he returns empty array?

  & lt ;? Php $ ch = curl_init (); Curl_setopt ($ ch, CURLOPT_URL, "http://www.1gom.us/ti-le-keo-malaysia.html"); Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true); $ Content = curl_exec ($ ch); Curl_close ($ ch); $ Regex = '/ & lt; Div class = "tabbox" id = "tabbox" & gt; (. *) & Lt; \ / div & gt; / '; Preg_match ($ regex, $ content, $ matches, PREG_OFFSET_CAPTURE, 3); $ Table = $ matches [1]; print_r ($ table); ? & Gt;    

You will get similar results. But if you use substr then you will create a new string for nothing, when the last parameter of preg_match only asks for the start of a search on the special offset of the subject string.

This is because you get an empty result, probably due to the fact that can not match with newlines by default You can change this behavior with the s modifier:

  $ regex = '~ & lt; Div class = "tabbox" id = "tabbox" & gt; (. *?) & Lt; / Div & gt; ~ S ';   

(Do not use different modifiers to avoid slash. Note also prevent the use of a non-reddening quantifier to be the first example of & lt; / div & gt; ; ) ) ) )

However, as seen in the comments, combo is easier with com dome dodod / domexpath to remove the information from an HTML document Depending on how your document looks and what you are trying to do).

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -