preg-match

No ending delimiter '/' found error

陌路散爱 提交于 2019-12-01 19:47:00
I have adjusted a small script to check backlinks. Yet I keep on getting the error Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in line 17. <?php function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } function google_backlink($uri) { $url = 'http://www.google.com/search?q=link:facebook.com&hl=en&filter=0'; $v = file_get_contents_curl($url); preg_match('/<div id="resultStats">About \(.*?)

No ending delimiter '/' found error

 ̄綄美尐妖づ 提交于 2019-12-01 18:49:58
问题 I have adjusted a small script to check backlinks. Yet I keep on getting the error Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in line 17. <?php function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } function google_backlink($uri) { $url = 'http://www.google.com/search?q=link:facebook

Matching with preg_match_all

十年热恋 提交于 2019-12-01 15:10:57
I got this regex: $val = "(123)(4)(56)"; $regex = "^(\((.*?)\))+$"; preg_match_all("/{$regex}/", $val, $matches); Can anyone please tell me why this matches only the last number (56) and not each set of numbers individually? This is what $matches contains after the above regex runs: array 0 => array 0 => string '(123)(4)(56)' (length=12) 1 => array 0 => string '(56)' (length=4) 2 => array 0 => string '56' (length=2) As @develroot already has answered the way you want to use preg_match_all does not work, it will only return the last matching group, not all captures of that group. That's how

Matching with preg_match_all

拈花ヽ惹草 提交于 2019-12-01 12:34:39
问题 I got this regex: $val = "(123)(4)(56)"; $regex = "^(\((.*?)\))+$"; preg_match_all("/{$regex}/", $val, $matches); Can anyone please tell me why this matches only the last number (56) and not each set of numbers individually? This is what $matches contains after the above regex runs: array 0 => array 0 => string '(123)(4)(56)' (length=12) 1 => array 0 => string '(56)' (length=4) 2 => array 0 => string '56' (length=2) 回答1: As @develroot already has answered the way you want to use preg_match

Regex to allow A-Z, - and '

≡放荡痞女 提交于 2019-12-01 12:09:11
问题 I am trying to get this Regex to work to validate a Name field to only allow A-Z, ' and -. So far I am using this which is working fine apart from it wont allow an apostrophe. if (preg_match("/[^a-zA-Z'-]+/",$firstname)) { // do something } I would like it to only allow A-Z, - (dash) and an ' (apostrophe). It works for the A-Z and the - but still wont work for the ' Could someone please provide an example? Thanks 回答1: if (preg_match("/^[A-Z'-]+$/",$firstname)) { // do something } The caret ^

preg_match to extract mailto on anchor

隐身守侯 提交于 2019-12-01 11:46:44
I need to get the email adress from an anchor with a mailto attribute with regex. this pattern: (.*)<a\s(.*?)(.*)\s*href\=['"]mailto:([-a-z0-9_]+)@([a-z0-9-]+).([a-z]+)['"]>(.*)</a>(.*) Works in regex coach though it doesnt work with PHP. Code: preg_match("'(.*)<a (.*?)(.*) *href\=['\"]mailto:([-a-z0-9_]+)@([a-z0-9-]+).([a-z]+)['\"]>(.*)</a>(.*)'si", "<a href=\"mailto:someemail@ohio.com\"">Some email</a>", $matches); print_r($matches); So why doenst it work in php? PHP’s PCRE require the regular expression to be wrapped into delimiters that separate the pattern from optional modifiers . In

a simple function for return number from string in php

Deadly 提交于 2019-12-01 11:32:27
I want capture Rank from this code : $RankStr = 'var trafficstatsSnippet = "/site/trafficstats;pysa1bpbPOVl6Wm5d4Zv4nKXKdM%3D /aahoonet.com/?adult=&category=&rank=1234567";' I use this code : $NewPOS = strpos($RankStr, "rank="); $SRank = substr($RankStr, $NewPOS + 5, 10); echo $SRank; because of RANK code variable from (1 - 25,000,000) , i use above code by selecting maximum 10 charachters after starting position of rank= plus 5 further index. so this function return 1234567"; and after that i want to grab this number from string. trying preg_match_all or regex but becasue of nofamiliarity

Get all nested curly braces

早过忘川 提交于 2019-12-01 11:11:26
It is possible to get all content in nested curly braces from string? For example: The {quick} brown fox {jumps {over the} lazy} dog So i need: quick over the jumps {over the} lazy Better in this sequence, from most nested. Solution The regex below will allow you to grab the content of all the nested curly braces. Note that this assumes that the nested curly braces are balanced; otherwise, it is hard to define what the answer should be. (?=\{((?:[^{}]++|\{(?1)\})++)\}) The result will be in capturing group 1. DEMO Note that the order is not as specified in the question, though. The order

preg_match to extract mailto on anchor

强颜欢笑 提交于 2019-12-01 08:25:44
问题 I need to get the email adress from an anchor with a mailto attribute with regex. this pattern: (.*)<a\s(.*?)(.*)\s*href\=['"]mailto:([-a-z0-9_]+)@([a-z0-9-]+).([a-z]+)['"]>(.*)</a>(.*) Works in regex coach though it doesnt work with PHP. Code: preg_match("'(.*)<a (.*?)(.*) *href\=['\"]mailto:([-a-z0-9_]+)@([a-z0-9-]+).([a-z]+)['\"]>(.*)</a>(.*)'si", "<a href=\"mailto:someemail@ohio.com\"">Some email</a>", $matches); print_r($matches); So why doenst it work in php? 回答1: PHP’s PCRE require the

a simple function for return number from string in php

痞子三分冷 提交于 2019-12-01 08:20:44
问题 I want capture Rank from this code : $RankStr = 'var trafficstatsSnippet = "/site/trafficstats;pysa1bpbPOVl6Wm5d4Zv4nKXKdM%3D /aahoonet.com/?adult=&category=&rank=1234567";' I use this code : $NewPOS = strpos($RankStr, "rank="); $SRank = substr($RankStr, $NewPOS + 5, 10); echo $SRank; because of RANK code variable from (1 - 25,000,000) , i use above code by selecting maximum 10 charachters after starting position of rank= plus 5 further index. so this function return 1234567"; and after that