preg-match-all

Get all video qualities from a block of text using a regex

别说谁变了你拦得住时间么 提交于 2019-12-02 21:54:35
问题 I want to get all video qualitys from string. My string: #EXTM3U #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=350000 128/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=750000 500/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1000000 750/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1250000 1000/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X

Getting the first image in string with php

我怕爱的太早我们不能终老 提交于 2019-12-02 17:08:59
I'm trying to get the first image from each of my posts. This code below works great if I only have one image. But if I have more then one it gives me an image but not always the first. I really only want the first image. A lot of times the second image is a next button $texthtml = 'Who is Sara Bareilles on Sing Off<br> <img alt="Sara" title="Sara" src="475993565.jpg"/><br> <img alt="Sara" title="Sara two" src="475993434343434.jpg"/><br>'; preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $texthtml, $matches); $first_img = $matches [1] [0]; now I can take this "$first_img" and stick it in

Regex to match a word, even is there are spaces between letters

痞子三分冷 提交于 2019-12-02 13:09:31
I'd like to have a regex to match a word, even if there are spaces between the characters. When I want to match the word test , it should match the following: test t est t e s t And so on, but it should not match things like this: tste te ts s tet I have this regex: (t[\s]*e[\s]*s[\s]*t[\s]*) But I don't believe that this one is very efficient. Actually, it is the same as t\s*e\s*s\s*t (if the word appears inside a larger string, \bt\s*e\s*s\s*t\b is preferable). This is the only way to match such words. You have to consume these spaces, otherwise you won't have a match. Why not remove all

php using curl and preg_match_all

可紊 提交于 2019-12-02 13:08:50
So what I'm wanting to do is use preg_match_all to pull the number from the table below. I've tried playing around with a few regular expressions, but I'm not getting it yet. I would like to pull the numbers and print them. ie. //gets the site $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://site.org'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); //parse the data preg_match_all('/[0-9]+(?=[^0-9]+(N7:0<|N7:10<|N7:20))/', $response, $matches); //prints the parsed data print_r($matches[0]); Any help would be great. <html><head><title>Monitor</title></head>

Regular expression to find all “src” attribute of HTML “img” element only folder in PHP

与世无争的帅哥 提交于 2019-12-02 13:04:18
I have a string, inside of that I have an image: "<img src="img/programacao/51.jpg" style="width:200px;" /><p>balbalba</p><img src="img/programacao/46.jpg" style="width:200px;" /><p>balbalba</p><img src="/img/finalCinerio.jpg"><p>balbalba</p><img src="img/topo.jpg" />" I just need the folder of images :img/programacao/ But my regex not working: preg_match_all('/<img.*?src="([^"]*)"[^>]*>(?:<img>)?/', $text, $image); Output ... [0] => img/topo.jpg [1] => img/p_veneza.png [2] => img/programacao/51.jpg [3] => img/programacao/46.jpg [4] => img/p_rio.png [5] => /img/finalCinerio.jpg [6] => img

Get all video qualities from a block of text using a regex

一世执手 提交于 2019-12-02 10:39:51
I want to get all video qualitys from string. My string: #EXTM3U #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=350000 128/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=750000 500/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1000000 750/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1250000 1000/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1750000 1500/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT

Matching Product Prices from an HTML text

喜夏-厌秋 提交于 2019-12-02 08:33:34
问题 I'm trying a simple regex on a string for pricing information, but my preg_match_all is simply not finding what it should. I'm looking for instance of e.g. $**.** or £**.** or sometimes the currency symbol might be encoded as an HTML entity e.g. for GBP £ or £ Is there an issue with using preg_match_all to find html entities? Here's what I'm trying: $price = preg_match_all( '#(?:\$|\£|\€|\£|\£)(\d+(?:\.\d+)?)#', $string, $matches ); But I get: Unknown modifier '1' 回答1: Here is some obvious

php using curl and preg_match_all [duplicate]

感情迁移 提交于 2019-12-02 07:34:48
This question already has an answer here: php using curl and preg_match_all 1 answer I feel like I am missing something. I am using the following code to pull some numbers from a table. As simple as it looks, I cannot seem to get anything to print. I am placing my code and an example of the table below. Please help me find my error. I want it to print out only the numbers in each cell. //gets the site $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://site.org'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); //parse the data preg_match_all('/<td align=right>(\d

Regex with possible empty matches and multi-line match

守給你的承諾、 提交于 2019-12-02 07:09:41
I've been trying to "parse" some data using a regex, and I feel as if I'm close, but I just can't seem to bring it all home. The data that needs parsing generally looks like this: <param>: <value>\n . The number of params can vary, just as the value can. Still, here's an example: FooID: 123456 Name: Chuck When: 01/02/2013 01:23:45 InternalID: 789654 User Message: Hello, this is nillable, but can be quite long. Text can be spread out over many lines And can start with any number of \n's. It can be empty, too. What's worse, though is that this CAN contain colons (but they're _"escaped"_ using `\

Php parse html dom and count specific rows

一个人想着一个人 提交于 2019-12-02 06:48:29
问题 I'm using the " Simple php DOM Parser " to parse an html table and count its row. I solved to count all the rows (tr) in it with this code: $rows = $table->find('.trClass'); $count = count($rows); echo $count; And I correctly get the number of all the rows in the table. Now I want to count only the rows which contains a specific td (with a specific string). We could assume that I want to count only the rows with this td: <td class="tdClass" align="center" nowrap="">TARGET STRING</td> How can