preg-match-all

How to match text inside starting and closing curly brace, the tags and the specified attributes

非 Y 不嫁゛ 提交于 2019-12-30 11:40:07
问题 I am implementing a plugin code for my CMS system. Something like a shortcode but will be applicable in many scenarios. I want a case where an admin writes his code like this: Example 1: {COMMAND_NAME}Strings of texts that conatains htmltags,symbols,just anything{/COMMAND_NAME} Example 2 {COMMAND_NAME} Example 3 {COMMAND_NAME{attriute1=value attribute2=value}} Example 4 {COMMAND_NAME{attriute1=value attribute2=value}}Strings of anything including texts, htmltags and anything at all {/COMMAND

How to parse column separated key-value text with possible multiline strings

怎甘沉沦 提交于 2019-12-30 07:22:41
问题 I need to parse the following text: First: 1 Second: 2 Multiline: blablablabla bla2bla2bla2 bla3b and key: value in the middle if strting Fourth: value Value is a string OR multiline string, at the same time value could contain "key: blablabla" substring. Such subsctring should be ignored (not parsed as a separate key-value pair). Please help me with regex or other algorithm. Ideal result would be: $regex = "/SOME REGEX/"; $matches = []; preg_match_all($regex, $html, $matches); // $mathes has

how to find only numbers in a array by using regexp in php?

吃可爱长大的小学妹 提交于 2019-12-25 17:05:40
问题 i am using $front->getRequest()->getParams() to get the url params. They look like this Zend_Debug::dump($front->getRequest()->getParams()); array(4) { ["id"] => string(7) "3532231" ["module"] => string(7) "test" ["controller"] => string(6) "index" ["action"] => string(5) "index" } i am interested in running this through preg_match_all to get back only the id numbers by using some regexp similar to ([\s0-9])+ for some reason i cant isolate that number. There is the possibility that there will

How to parse to string to multidimensional array (regex?)

淺唱寂寞╮ 提交于 2019-12-25 08:08:03
问题 I need to pass the data to an array by blocks, how can I make this? Do I need to use regex? My script gives me errors because I can not separate it as I wish. Does anyone have any ideas? Data: ~0 11111111 ~1 222222222 ~2 3333333333 ~end ~0 aaaaaaaaaaa ~1 bbbbbbbbbb ~2 cccccccccc ~3 ddddddddddd ~end ~0 yyyyyyyyyyy xxxxxxxx ffffffffff ~1 rrrrrrrrrrrr ~end I need it like this: Array ( [0] => Array ( [0] => 11111111 [1] => 222222222 [2] => 3333333333 ) ), [1] => Array ( [0] => aaaaaaaaaaa [1] =>

Image tag scraper regular expression

ぃ、小莉子 提交于 2019-12-25 03:21:36
问题 I'm really REALLY bad at regular expressions. It just hasn't clicked yet. I'm trying to make small application that extracts all image tags of their src, width, and height attributes. This is what I have so far: <?php function print_links ($url) { $fp = fopen($url, "r") or die("Could not contact $url"); $page_contents = ""; while ($new_text = fread($fp, 100)) { $page_contents .= $new_text; } $match_result = preg_match_all( '/<img.*src=[\"\'](.*)[\"\'].*width=(\d+).*height=(\d+).*/>/i', $page

preg_match_all: Warning: preg_match_all(): Unknown modifier '(' in [duplicate]

我只是一个虾纸丫 提交于 2019-12-25 02:25:23
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: preg_match() Unknown modifier '[' help I am trying to match this pattern $regex_pattern = '<td id="(\w+)" class="(\w+)">(\w+).com<\/td>'; preg_match_all($regex_pattern, $result, $matches); print_r($matches); But I am getting this error: Warning: preg_match_all(): Unknown modifier '(' in What's wrong in my regex pattern? 回答1: Add delimiters to your pattern When using the PCRE functions, it is required that the

regex to pull all attributes out of all meta tags

微笑、不失礼 提交于 2019-12-24 14:09:48
问题 I'm trying to pull meta tags out of a html page, to compare two pages (live and dev) to see if they're SEO is the same after a site redesign/refactor. I need to compare title, meta tags (description, opengraph etc.), h1's, our analytics (Omniture), and our ad tags (doubleclick) are all the same. My problem is getting meta tags http://php.net/manual/en/function.get-meta-tags.php only works if they have a name= attribute, same with "mariano at cricava dot com"'s solution. I don't want to

find pattern for url with no ending slash

不打扰是莪最后的温柔 提交于 2019-12-24 14:03:12
问题 I'm looking for preg_match_all pattern to find all URL on a page that don't have trailing slash. For example: if I have a href="/testing/abc/">end with slash a href="/testing/test/mnl">no ending slash The result would be #2 Thanks. 回答1: Better extract all your href links using DOM parser and see if URL is ending with slash or not. No regex needed for that. For the regex solution for the examples provided you can use this regex: /href=(['"])[^\s]+(?<!\/)\1/ Live Demo: http://www.rubular.com/r

How to insert in a database an array got by preg_match_all

时光毁灭记忆、已成空白 提交于 2019-12-24 06:03:21
问题 I've just got an array using preg_match_all and i tried to insert it to a table using this code: $casturl = "https://www.themoviedb.org/movie/353491-the-dark-tower/cast"; $cast = file_get_contents($casturl); preg_match_all('#<img class="profile lazyload fade" data-sizes="auto" data-src="(.*?)" data-srcset="#' , $cast , $castimg ); print_r($castimg[1]); $escaped_values = array_map('mysql_real_escape_string', array_values($castimg)); $values = implode(", ", $escaped_values); $sql = "INSERT INTO

How to insert in a database an array got by preg_match_all

无人久伴 提交于 2019-12-24 06:02:39
问题 I've just got an array using preg_match_all and i tried to insert it to a table using this code: $casturl = "https://www.themoviedb.org/movie/353491-the-dark-tower/cast"; $cast = file_get_contents($casturl); preg_match_all('#<img class="profile lazyload fade" data-sizes="auto" data-src="(.*?)" data-srcset="#' , $cast , $castimg ); print_r($castimg[1]); $escaped_values = array_map('mysql_real_escape_string', array_values($castimg)); $values = implode(", ", $escaped_values); $sql = "INSERT INTO