preg-match

PHP preg_match_all returns nothing

I am trying to extract all img tags from an HTML string. See the code $d1 = file_get_contents("http://itcapsule.blogspot.com/feeds/posts/default?alt=rss"); preg_match_all('/<img[^>]+>/i',$d1,$result); print_r($result); And the result is Array ( [0] => Array ( ) ) But the same regex gives correct result in an online regex test...

preg_match multiple help?

<?PHP $string = "[test]aaaaa[/[test][test]bbbb[/test][test]cccc[/test][test]ddd[/test]"; echo $string . "<br>"; preg_match("/\[test\].*?(\[\/test\])/i", $string, $m); print_r($m); ?> how to get value aaaaa and bbbb in multiple from capture [test] and [/test] ? ...

preg_match_all image source

I have the following regex expression which is to extract the source of any img tag in HTML. /(<img).*(src\s*=\s*"([a-zA-Z0-9\.;:\/\?&=\-_|\r|\n]{1,})")/isxmU However, it doesn't appear to be matching the following: <IMG SRC='http://www.mysite.com/pix/lens/mtf/CAEF8512L.gif'&gt; How can I build it to match this as well? ...

preg_match matching multiple matches

I'm trying to use preg_match to extract info from href="domain.com/subdir/?key=value The info I want are domain.com subdir key value Can someone suggest what is the correct way to write the preg_match statement? Thanks! ...

PHP: using REGEX to get the tablename from a mysql query

Hi Guys, Consider these three mysql statements: select * from Users; select id, title, value from Blogs; select id, feelURL, feelTitle from Feeds where id = 1; Now im not very good at REGEX, but i want to get the table name from the mysql query. Could someone possibly create one for me with a little explanation. Thanks, ...

PHP's preg_match() equivalent in C++?

Hello there, My question is simple. Is there a PHP's preg_match() function equivalent in the C++ STL? If not, can you tell me an alternative? Thanks. ...

How do I extract specific data with preg_match?

I'm looking to extract values from a whole load of html (i've just trimmed down to the relevant data), there are multiple 'select' elements, and only want to extract those who's 'name' element matches the name 'aMembers'. So the resulting values I would like to retrieve are 5,10,25 and 30 (see below) how can I achieve this with preg_matc...

Complex regex question, data may or may not be in brackets

I need to extract data from a source that presents it in one of two ways. The data could be formatted like this: Francis (Lab) 18,077 (60.05%); Waller (LD) 4,140 (13.75%); Evans (PC) 3,545 (11.78%); Rees-Mogg (C) 3,064 (10.18%); Wright (Veritas) 768 (2.55%); La Vey (Green) 510 (1.69%) Or like this: Lab 8,994 (33.00%); C 7,924 (29.07%...

How to extract only part of string in PHP?

I have a following string and I want to extract image123.jpg. ..here_can_be_any_length "and_here_any_length/image123.jpg" and_here_also_any_length image123 can be any length (newimage123456 etc) and with extension of jpg, jpeg, gif or png. I assume I need to use preg_match, but I am not really sure and like to know how to code it or ...

preg_match_all to parse an xml-like attribute string

I have a string like so: option_alpha="value" option_beta="some other value" option_gamma="X" ...etc. I'm using this to parse them into name & value pairs: preg_match_all("/([a-z0-9_]+)\s*=\s*[\"\'](.+?)[\"\']/is", $var_string, $matches) Which works fine, unless it encounters an empty attribute value: option_alpha="value" option_b...

Regular Expression to match unlimited number of options

I want to be able to parse file paths like this one: /var/www/index.(htm|html|php|shtml) into an ordered array: array("htm", "html", "php", "shtml") and then produce a list of alternatives: /var/www/index.htm /var/www/index.html /var/www/index.php /var/www/index.shtml Right now, I have a preg_match statement that can split two...

Help on preg_match pattern

I want to parse a html content that have something like this: <div id="sometext">Lorem<br> <b>Ipsun</b></div><span>content</span><div id="block">lorem2</div> I need to catch just the "Lorem<br> <b>Ipsun</b>" inside the first div. How can I achieve this? Ps: the html inside the first div have multiple lines, its an article. Th...

Erroneous Matches with Regular Expression

$regexp = '/(?:<input\stype="hidden"\sname="){1}([a-zA-Z0-9]*)(?:"\svalue="1"\s\/>)/'; $response = '<input type="hidden" name="7d37dddd0eb2c85b8d394ef36b35f54f" value="1" />'; preg_match($regexp, $response, $matches); echo $matches[1]; // Outputs: 7d37dddd0eb2c85b8d394ef36b35f54f So I'm using this regular expression to search for an a...

Use regular expressions to match an ? but not a \?

I have a PHP regular expression that has been functioning fairly well to parse some odd legacy client templates until recently when we found an escaped question mark (\?) included in a template expression. I'm not strong enough with my regular expression-fu to wrap my feeble noodle around a negative look ahead or some techno-mumbo-jumbo ...

Detect remote charset in php

Hello, I would like to determine a remote page's encoding through detection of the Content-Type header tag <meta http-equiv="Content-Type" content="text/html; charset=XXXXX" /> if present. I retrieve the remote page and try to do a regex to find the required setting if present. I am still learning hence the problem below... Here is ...

Is there a way to pass another parameter in the preg_replace_callback callback function?

mmmh guys, i really hope my english is good enaught to explain what i need. Lets take this example (that is just an example!) of code: class Something(){ public function Lower($string){ return strtolower($string); } } class Foo{ public $something; public $reg; public $string; public function __construct(...

preg_replace only part of match

Hi, I'm using preg_replace to create urls for modrewrite based paging links. I use: $nextURL = preg_replace('%/([\d]+)/%','/'.($pageNumber+1).'/',$currentURL); which works fine, however I was wondering if there is a better way without having to include the '/' in the replacement parameter. I need to match the number as being between t...

Preg_match differences?

Hi, i want to ask, what is the meaning or difference between these two line? if( preg_match_all('/\#([א-תÀ-ÿ一-龥а-яa-z0-9\-_]{1,50})/iu', $message, $matches, PREG_PATTERN_ORDER) ) { if( preg_match_all('/\#([а-яa-z0-9\-_\x{4e00}-\x{9fa5}]{1,50})/iu', $message, $matches, PREG_PATTERN_ORDER) ) { and what does the number 3 mean in this l...

Help with a simple switch statement

I need to find the value of a variable and use it to add a class to a div, based on a switch statement. For example, my variable is $link and if $link has google.com IN IT at all, I need $class to equal 'google', if $link as yahoo.com IN IT at all, $class then needs to equal 'yahoo' So, I need something like this, but I'm not sure how...

Searching within an array of strings...

Ok, I'm feeling retarded here, I have a string like so: $string = 'function module_testing() {'; or it could be like this: $string = 'function module_testing()'; or it could be like this: $string = 'function module_testing($params) {'; or this: $string = 'function module_testing($params, $another = array())'; and many more w...