preg-match

How to get text in array between all <span> tag from HTML?

本小妞迷上赌 提交于 2019-12-06 20:06:22
问题 I want to fetch text in array between all <span> </span> tag from HTML, I have tried with this code but it returns only one occurrence : preg_match('/<span>(.+?)<\/span>/is', $row['tbl_highlighted_icon_content'], $matches); echo $matches[1]; My HTML: <span>The wish to</span> be unfairly treated is a compromise attempt that would COMBINE attack <span>and innocen</span>ce. Who can combine the wholly incompatible, and make a unity of what can NEVER j<span>oin? Walk </span>you the gentle way, My

preg_match coordinates with degree sign

情到浓时终转凉″ 提交于 2019-12-06 16:09:01
I am trying to capture the coordinates of an input that could look like this 22°50'23.46"S, 43° 0'44.80"W or this 41°12'27.84"N, 16°18'40.15"E I think the problem is the degree symbols in my pattern. My current code: $found = preg_match("~(\d+\p{Sm}\d+\s*\'\s*\d+\s*\.\s*\d+\s*\"\s*[N|S])\s*,\s*(\d+\s*\p{Sm}\s*\d+\s*\'\s*\d+\s*\.\s*\d+\s*\"\s*[E|W])~i", $_POST['submission']['url'], $matches); $matches stays empty. Perhaps you should try ignoring the actual degrees and tick marks and focus just on the data you want to grab. (\d+)\D+(\d+)\D+(\d+)\.(\d+)\W(\w+)\W+(\d+)\D+(\d+)\D+(\d+)\.(\d+)\W(\w)

Regex to find Youtube Link in string [duplicate]

China☆狼群 提交于 2019-12-06 14:35:48
This question already has answers here : How do I find all YouTube video ids in a string using a regex? (10 answers) Closed 4 years ago . I have a string like that: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, https://www.youtube.com/watch?v=7TL02DA5MZM when an unknown printer took a galley of type and scrambled it to make a type This is what I have: preg_match("(?:http://)?(?:www.)?(?:youtube.com|youtu.be)/(?:watch\?)?([^\s]+?)", $content, $m); var_dump( $m ); and want to extract the

PHP to SEARCH the Upper+Lower Case mixed Words in the strings?

不羁岁月 提交于 2019-12-06 14:25:35
Lets say there is a string like: A quick brOwn FOX called F. 4lviN The WORDS i want TO SEARCH must have the following conditions: The words containing MIXED Upper & Lower Cases Containing ONLY alphabets A to Z (A-Z a-z) (e.g: No numbers, NO commas, NO full-stops, NO dash .. etc) So suppose, when i search (for e.g in this string), the search result will be: brOwn Because it is the only word which contains both of Upper & Lower Case letters inside (and also containing only alphabets). So how can I make it work in php? You should be good with: preg_match_all("/\b([a-z]+[A-Z]+[a-zA-Z]*|[A-Z]+[a-z]

Get number before selected word form string using preg_match function in php

只愿长相守 提交于 2019-12-06 14:01:18
I am trying to get the mm and inches values from the following string using preg_match . $string = "Gold 5.0mm Rolo Chain 18" In"; How can I do this? Regex: ([\d\.]+)(?:mm|\") ([\d\.]+)(?:mm|\") This will match digits , . before mm and " . PHP code demo <?php ini_set('display_errors', 1); $string='Gold 5.0mm Rolo Chain 18" In'; preg_match_all("/([\d\.]+)(?:mm|\")/", $string,$matches); print_r($matches);// its 1 index will return your desired result Or: Regex: /[\d\.]+(?=mm|\")/ [\d\.]+(?=mm|\") match digits , . and positively look ahead for mm and " PHP code demo <?php ini_set('display_errors'

preg_match function for phone numbers

折月煮酒 提交于 2019-12-06 12:43:12
问题 I have some troubles matching a phone number with this function return (bool)preg_match( '/^[\-+]?[0-9]+$/', $num); The above function always returns false after stripping brackets ( ) and dash - am left with +1234567890 what am i missing 回答1: Test Here: https://eval.in/84659 $p = '/[\-+]?[0-9]+$/'; $num ='+1234567890'; echo preg_match( $p, $num)." "; $num1 ='+1234567890d'; echo preg_match( $p, $num1)." "; $num1 ='-1234567890'; echo preg_match( $p, $num1)." "; OUTPUT: 1 0 1 回答2: You probably

php: how to find numbers in string?

a 夏天 提交于 2019-12-06 11:20:34
I have some strings like: some words 1-25 to some words 26-50 more words 1-10 words text and words 30-100 how can I find and get from string all of the "1-25" and the "26-50" and more If it’s integers, match multiple digits: \d+ . To match the whole range expression: (\d+)-(\d+) . Maybe you also want to allow whitespace between the dash and the numbers: (\d+)\s*-\s*(\d+) And maybe you want to make sure that the expression stands free, i.e. isn’t part of a word: \b(\d+)\s*-\s*(\d+)\b \b is a zero-width match and tests for word boundaries. This expression forbids things like “ Some1 -2text ” but

How can I adapt my regex to allow for escaped quotes?

大兔子大兔子 提交于 2019-12-06 10:08:33
问题 Introduction First my general issue is that I want to string replace question marks in a string, but only when they are not quoted. So I found a similar answer on SO (link) and began testing out the code. Unfortunately, of course, the code does not take into account escaped quotes. For example: $string = 'hello="is it me your are looking for\\"?" AND test=?'; I have adapted a regular expression and code from that answer to the question: How to replace words outside double and single quotes,

How can I extract certain HTML tags e.g. <ul> using Regex with preg_match_all in PHP?

耗尽温柔 提交于 2019-12-06 09:25:34
I am new to regular expressions. I want to fetch some data from a web page source. I used file_get_contents("url") to get the page's HTML source. Now I want to capture a portion within some special tags. I found preg_match_all() works for this. Now I want some help to solve my problem and if possible help me to find out how to solve similar problems like this. In the example below, how would I get the data within the <ul> ? (I wish this sample HTML code could be easier for me to understand.) <div class="a_a">qqqqq<span>www</span> </div> <ul> <li> <div class="a_a"><h3>aaaa</h3> aaaa aaaaa</div>

preg_match returns identical elements only once

北慕城南 提交于 2019-12-06 09:21:35
I am going through a string and proces all the elements between !-- and --!. But only unique elements are processes. When I have !--example--! and a bit further in the text also !--example--!, the second one is ignored. This is the code: while ($do = preg_match("/!--(.*?)--!/", $formtext, $matches)){ I know about preg_match_all, but need to do this with preg_match. Any help? Thanks in advance! You'll want PHP to look for matches only after the previous match. For that, you'll need to capture string offsets using the PREG_OFFSET_CAPTURE flag. Example: $offset = 0; while (preg_match("/!--(.*?)--