preg-match

php cURL. preg_match , extract text from xhtml

蹲街弑〆低调 提交于 2019-12-25 01:25:35
问题 I'm trying to extract the price from the bellow html page/link using php cURL and preg_match . Basically I'm expecting for this code to output 4,550 but for some reasons I get Notice: Undefined offset: 1 in C:\wamp\www\test.php on line 22 I think that the pattern is correct because if I put the html itself in a variable and escape the "" it works ! . Also if I output (echo $result;) it displays the html properly grabbed from foxtons website so I just can't figure it out why the whole thing

Simple phone number regex for php

别等时光非礼了梦想. 提交于 2019-12-24 20:42:32
问题 I've been looking for a simple phone number regex that will match just this format: (XXX) XXX-XXXX <---with the parentheses and the space after them required For the life of me, I can't figure out why this wont work (This was one that I tried making myself and have been tinkering with for hours): ^[\(0-9\){3} [0-9]{3}-[0-9]{4}$ I've looked everywhere online for a regex with that particular format matching to no avail. Please help? 回答1: The following regex works ^\(\d{3}\) \d{3}-\d{4}$ ^ =

preg_match get src of img with specific class

霸气de小男生 提交于 2019-12-24 19:37:56
问题 Let's say i have many images in a string and i only want to get the src of the image with a specific class <img src="image1.jpg"/> <img src="image2.jpg"/> <img src="image3.jpg" class="main"/> I wanted to get the src of the third one, which has a class main . How do i do that? $pattern = '/< *img[^>]*src *= *["\']?([^"\']*)/i'; preg_match($pattern,$response,$matches); this one matches all img tags. 回答1: Don't use a regex to parse HTML. Use DOMDocument instead. Here's some code: $dom = new

Prevent dollar sign to be added from certain strings [duplicate]

馋奶兔 提交于 2019-12-24 17:05:11
问题 This question already has answers here : Adding dollar sign before each string in array? (2 answers) Closed 5 years ago . I have this this array; Array ( [0] => ( [1] => he [2] => + [3] => is [4] => + [5] => genius [6] => ) [7] => * [8] => and [9] => / [10] => clever ) It was possibe to put dollar sign before each alphanumeric string in array, the link is here : Adding dollar sign before each string in array? Now, Is it possible to prevent dollar sign to be added to a certain strings, for

How to match PHP tags with Regex? [closed]

我的梦境 提交于 2019-12-24 13:39:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm not that good at Regex, Can you give me a pattern to match any php tags? [ <? , <?php ] if you have a nice and simple guide for Regex i'd be happy to have it too :) I already tried: '/^(<\?)$/' But it doesn't really help =/ Thanks! 回答1: You will need preg_match_all to match tags, plural. The below will match

PHP eregi() is deprecated detect browser [duplicate]

可紊 提交于 2019-12-24 11:48:01
问题 This question already has answers here : How can I convert ereg expressions to preg in PHP? (4 answers) Closed 5 years ago . I have a function to detect browser with version: # Agent - Webbrowsers function agent_browser($http_user_agent) { // Browsers $browsers = array ( 'Android Standaard' => '(Linux)(.*)(Android)(.*)(Mobile Safari)', 'MSIE 10' => '(MSIE 10)', 'MSIE 9' => '(MSIE 9)', 'MSIE 8' => '(MSIE 8)', 'MSIE 7' => '(MSIE 7)', 'MSIE 6' => '(MSIE 6)', 'MSIE 5' => '(MSIE 5)', 'Opera 12' =>

How to replace eregi()

好久不见. 提交于 2019-12-24 09:58:41
问题 I tried looking around and thought i figured it out by using preg_match , but preg match gives me the error: Warning: preg_match(): No ending delimiter '^' here is my original code which php says is depreciated: if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { $erroR= "Invalid Email address"; } can someone explain what the ending delimiter '^' is, and how to add it. thanks@ 回答1: Swap eregi() with preg_match() , and add delimiters to the

PHP preg_match Regular Expression Improvement

感情迁移 提交于 2019-12-24 09:52:32
问题 Hello All , I am trying to widen the scope on a preg_match I currently use in a shoutbox. I am struggling to build on my current regular expression to obtain the desired identification. Please see the current regex I am using followed by some information on the matches I would like to achieve. Current regular expression: ~\bf+(?:\.+|\s+)?r+(?:\.+|\s+)?e+(?:\.+|\s+)?d+(?:\.+|)?\b~i Desired match info: [01] Lorem ipsum dolor fred sit amet. Identify key word . [02] Lorem ipsum dolor $fred sit

Arabic characters using preg_match() function

有些话、适合烂在心里 提交于 2019-12-24 09:01:37
问题 I am trying to use preg_match() to check Arabic and English characters only, i used this code: preg_match("/^[a-zA-Zأ-ي]*$/",$name) but still, it is not working. EDIT: The code that does not work: if($name == '' || $email =='') { echo("<div class=\"error\">fill all fields</div>"); } else if (!preg_match("/^[a-zA-Zأ-ي\s]*$/",$name)) { echo("<div class=\"error\">Only letters and white space allowed</div>"); } else if (strlen($name) < 6) { echo("<div class=\"error\">NONONONO les than 6</div>");

PHP: How can I make preg_match match only the first occurrence?

三世轮回 提交于 2019-12-24 08:42:03
问题 preg_match($pattern, $subject, $matches), $matches seems to be an array of all matches, I only need the first occurrence of the regex pattern, and I want the matching to stop right away once it finds a match and store it in $matches. Is it possible? Thank you. I'm not talking about greedy match(.* and .*?), an example is as follows, $str = 'abcd,abed,abfd,abgd'; preg_match("/ab.d/", $str, $match); I want it to find only abcd and not any of the further matches, for further matches are useless