preg-match-all

php preg match all, all the `p`

半城伤御伤魂 提交于 2020-02-06 09:25:52
问题 <?php $str= <<<ETO <p>one two</p> <p>three</p> ETO; preg_match_all('/<p>(.*?)<\/p>/',$str,$r); print_r($r); ?> I am studying preg_match_all . I want get all the p from one article. but my code only get the second p . how to modify so that I can get the first p , either. Thanks. 回答1: You are missing the /ims flag at the end of your regex. Otherwise . will not match line breaks (as in your first paragraph). Actually /s would suffice, but I'm always using all three for simplicity. Also, preg

How to write nested regex to find words below some string?

耗尽温柔 提交于 2020-02-02 13:14:06
问题 I am converting one pdf to text with xpdf and then find some words with help of regex and preg_match_all. I am seperating my words with colon in pdftotext. Below is my pdftotext output: In respect of Shareholders Name: xyx Residential address: dublin No of Shares: 2 Name: abc Residential address: canada No of Shares: 2 So i write one regex that will show me words after colon in text(). $regex = '/(?<=: ).+/'; preg_match_all($regex, $string, $matches); But Now i want regex that will display

Regex multiline mode with optional group skip valid data

Deadly 提交于 2020-01-30 08:45:26
问题 Consider next example: $payload = ' ababaaabbb =%= ababaaabbb =%= ababaa =%= '; $pattern = '/^[ab]+\s*(?:=%=)?$/m'; preg_match_all($pattern, $payload, $matches); var_dump($matches); Expected and actual result of match is: "ababaaabbb =%=" "ababaaabbb =%=" "ababaa =%=" But if $payload changed to $payload = ' ababaaabbb =%= ababaaabbb =%= ababaa =%'; // "=" sign removed at EOL actual result is "ababaaabbb =%=" "ababaaabbb =%=" but expected is "ababaaabbb =%=" "ababaaabbb =%=" "ababaa " Why this

preg_match_all doesn't match when using a carat (^)

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-21 13:56:32
问题 I'm using preg_match_all to find a URL in a HTML file. The URL always appears at the start of the line, with no leading space, like this: <A HREF="/link/to/here"><strong>Next</strong></A> I used this to match it: preg_match_all('|^<A HREF="(?<url>.*?)"><strong>Next</strong>|', $html, $url_matches); It didn't work until I removed the carat (^) character. I thought that the carat matched the start of a line. Why is it causing my match to fail? 回答1: You have to add the m modifier: preg_match_all

Using regular expression subpattern to instead of using regular expression 2 times in php

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-16 19:17:08
问题 I'm interested if its possible to make include subpattern (child pattern) into a another pattern that would allow me to convert those 2 preg_match and preg_match_all into one preg_match/preg_match_all. <?php $data = 'office phones tel1 6665555998 tel2 555666888 tel3 555688855 home phones tel1 555222555 tel2 555222444 tel3 555666888'; preg_match('/phones(.*)home phones/', $data, $matches); // 1st operation preg_match_all('/[0-9]{4,12}/', $matches[1], $matches); // 2nd operation var_dump(

preg_match_all string from file with value

非 Y 不嫁゛ 提交于 2020-01-16 04:13:28
问题 I need to search into file name lll.php about content of option by value as my file lll.php <option value="n-7069">1</option> <option value="n-7066">3</option> <option value="n-7065">2</option> I try this code but not work with me my search code like n-7065 $ccc2=$rd33fddf33do['contery'] ; my file content value $llll= file_get_contents('lll.php'); but it now work with me preg_match_all('|<option *?</option>|ms', $llll, $matches); foreach ($matches[0] as $select) { preg_match_all('|value='.

how to select image src using PHP

╄→尐↘猪︶ㄣ 提交于 2020-01-15 18:54:36
问题 So i have some images with several forms like this : <a href="" class="link-img" alt=""> <img editable="true" style="display: block; cursor: default;" class="main-image" width="538" height="auto" src="src" alt="large image"> </a> and like this : <a href="" class="link link-img"> <img src="src" style="width: 100%; display: block; cursor: pointer;" editable="true" class="main-image imageLink" width="" height="auto" alt=""> </a> so my code to select the src image is : $c = preg_replace('/<a href

how to select image src using PHP

£可爱£侵袭症+ 提交于 2020-01-15 18:53:14
问题 So i have some images with several forms like this : <a href="" class="link-img" alt=""> <img editable="true" style="display: block; cursor: default;" class="main-image" width="538" height="auto" src="src" alt="large image"> </a> and like this : <a href="" class="link link-img"> <img src="src" style="width: 100%; display: block; cursor: pointer;" editable="true" class="main-image imageLink" width="" height="auto" alt=""> </a> so my code to select the src image is : $c = preg_replace('/<a href

how to select image src using PHP

≯℡__Kan透↙ 提交于 2020-01-15 18:52:48
问题 So i have some images with several forms like this : <a href="" class="link-img" alt=""> <img editable="true" style="display: block; cursor: default;" class="main-image" width="538" height="auto" src="src" alt="large image"> </a> and like this : <a href="" class="link link-img"> <img src="src" style="width: 100%; display: block; cursor: pointer;" editable="true" class="main-image imageLink" width="" height="auto" alt=""> </a> so my code to select the src image is : $c = preg_replace('/<a href

how to select image src using PHP

随声附和 提交于 2020-01-15 18:52:12
问题 So i have some images with several forms like this : <a href="" class="link-img" alt=""> <img editable="true" style="display: block; cursor: default;" class="main-image" width="538" height="auto" src="src" alt="large image"> </a> and like this : <a href="" class="link link-img"> <img src="src" style="width: 100%; display: block; cursor: pointer;" editable="true" class="main-image imageLink" width="" height="auto" alt=""> </a> so my code to select the src image is : $c = preg_replace('/<a href