preg-match

PHP preg_match to find and locate a dynamic URL from HTML Pages

吃可爱长大的小学妹 提交于 2019-12-12 01:27:50
问题 I need help with a REGEX that will find a link that comes in different formats based on how it got inserted to the HTML page. I am capable of reading the pages into PHP. Just not able to the right REGEX that will find URL and insulate them. I have a few examples on how they are getting inserted. Where sometimes they are plain text links, some of wrapped around them. There is even the odd occasion where text that is not part of the link gets inserted without spacing. Both Article ID and

preg_match return longest match

两盒软妹~` 提交于 2019-12-12 01:26:16
问题 I am trying to return a series of numbers between 5 and 9 digits long. I want to be able to get the longest possible match, but unfortunately preg_match just returns the last 5 characters that match. $string = "foo 123456"; if (preg_match("/.*(\d{5,9}).*/", $string, $match)) { print_r($match); }; will yield results Array ( [0] => foo 123456 [1] => 23456 ) 回答1: Since you want only the numbers, you can just remove the .* from the pattern: $string = "foo 123456"; if (preg_match("/\d{5,9}/",

preg_match for information in parentheses

北城余情 提交于 2019-12-12 01:22:27
问题 (ACCTG) Accounting The text above I trying to get the information in the parentheses how would I do that in php this is what I have so far. $regex = '#\((([^()]+|(?R))*)\)#'; if (preg_match_all($regex, $string ,$matches)) { echo implode(' ', $matches[1]); } else { //no parenthesis echo $string; } 回答1: I do converting special characters to hex for easy use in my regex's <? $input = 'abc ("an example")'; if(preg_match("/\x28([^\x29]+)\x29/", $input, $matched)) { //... print_r($matched); } else

Commas in preg_match string of words

ε祈祈猫儿з 提交于 2019-12-12 01:13:49
问题 I store a list of of bad words I want to filter posts against before I store them in the database. I store the bad words in an array that I implode with a pipe delimiter to do the check once. $bad_words_regex = "/\b" . implode('|', config_item('bad_words')) . "\b/"; if( preg_match(strtolower($bad_words_regex), strtolower(trim($message))) == FALSE ) { // save to database } I noticed messages with commas did not get saved to the database. I imagine there are other characters I should check for

How can I make the Segment router sanely process constraints in ZF2?

不想你离开。 提交于 2019-12-11 23:49:53
问题 I'm using the Segment router as a child of one of my main Literal routes in a ZF2 (currently using 2.3.5) application. The router needs to be able to handle Turkish input characters coming in from the URL. My first attempt looked something like this (as a child route): 'book' => array( 'type' => 'Zend\Mvc\Router\Http\Segment', 'options' => array( 'route' => 'kitap/:book[/]', 'constraints' => array( 'book' => '[a-zA-ZçÇşŞğĞıİöÖüÜ1-3.+ ]+', ), ), ), This mostly worked for everything I needed it

preg_match url get parameter parsing

戏子无情 提交于 2019-12-11 22:14:45
问题 I am trying to extract the latitude and longitude of a google maps url. Such an url could look like this: $url = 'http://maps.google.com/?ie=UTF8&ll=39.811856,11.309322&spn=0,0.485802&t=h&z=12&layer=c&cbll=39.311856,11.519322&panoid=1hltSSOoqv5H1dVKZWFkaA&cbp=13,117.95,,1,16.71'; As you can see, there's several location sets in the url. The cbll variable seems to be the right one in my case. This is what I came up with: preg_match("~&cbll=(-?\d+\.?\d*),(-?\d+\.?\d*)~", $url, $matches); The

PregMatch no ending ')' delimiter found

我们两清 提交于 2019-12-11 22:09:45
问题 I get the following error running a pattern matching validation: ErrorException [ Warning ]: preg_match() [function.preg-match]: No ending matching delimiter ')' found The PREG regex that I use has been taken from on online regex library but I can't find where the missing delimiter is. Is anyone able to point it out please? Checks UK Post Codes: (((^[BEGLMNS][1-9]\d?)|(^W[2-9])|(^(A[BL]|B[ABDHLNRST]|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]|F[KY]|G[LUY]|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]|M[EKL

Catching ids and its values from a string with preg_match

左心房为你撑大大i 提交于 2019-12-11 20:15:14
问题 I was wondering how can I create preg_match for catching: id=4 4 being any number and how can I search for the above example in a string? If this is could be correct /^id=[0-9]/ , the reason why I'm asking is because I'm not really good with preg_match . 回答1: for 4 being any number, we must set the range for it: /^id\=[0-9]+/ \ escape the equal-sign, plus after the number means 1 or even more. 回答2: You should go with the the following: /id=(\d+)/g Explanations: id= - Literal id= (\d+) -

preg_match to find a word that ends in a certain character

浪尽此生 提交于 2019-12-11 19:29:38
问题 I am trying to make a small program that searches within a timer (with this format 00d 00h 00m 00s) and returns the days into one variable, the hours into another, etc. This is some of my code: $time1 = "Left: 11d 21h 50m 06s <\/div>" preg_match_all("/ .*d/i", $time1, $timematch); // Day $time1day = $timematch[1]; // Saves to variable preg_match_all("/ .*h/i", $time1, $timematch); // Hour $time1hour = $timematch[1]; // Saves to variable preg_match_all("/ .*m/i", $time1, $timematch); // Minute

Detecting Android Browser (from v. 1 to 2.3 firmware) in PHP

情到浓时终转凉″ 提交于 2019-12-11 19:17:10
问题 I need to detect if the browser is Android (only from 1 to version 2.3), would this work? if(preg_match('/Android [1-2.3]/', $_SERVER['HTTP_USER_AGENT'])) { echo 'something'; } 回答1: Following Regex can match exactly Android [1-2.3] . Android ([1](?:\.[0-9])?|[2](?:\.[0-3])?$) For MSIE [6-8] Android [1-2.3] MSIE [6-8] Android ([1](?:\.[0-9])?|[2](?:\.[0-3])?)$ Running regex here 回答2: I don't know really know what the UserAgents for those devices look like, but the pattern you have is not