preg-match

Any preg_match() to extract image urls from text ?

Hi, i need a preg_match() syntax or something similar to extract JPG or PNG or GIF URLs from a mixed text and put them in an array or at last store the first url. maybe some syntax which searchs for strings that are beginning with http and ending with jpg/png/gif.. i believe it can be done with preg_match() Note: the text can be like ...

Bug in my preg-match

Hai all i have a big problem right now i have this sample code: preg_match_all("/\[BLOG\=\[(.*)]](.*)\[\/BLOG]/U", $this->soruces , $match_list ); and i don't know why its not will working, its print this out to me Array ( [0] => GROUPID=23|CATID=28|SORT=ASE [1] => GROUPID=23|CATID=29|SORT=ASE [2] => GROUPID=23|CATID=30|SORT=ASE ) ...

Matching SRC attribute of IMG tag using preg_match

I'm attempting to run preg_match to extract the SRC attribute from the first IMG tag in an article (in this case, stored in $row->introtext). preg_match('/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\']*)/i', $row->introtext, $matches); Instead of getting something like images/stories/otakuzoku1.jpg from <img src="images/stories/otak...

preg_match a "shortcode" to create an array with semantic array keys.

How would I preg_match the following piece of "shortcode" so that video and align are array keys and their values are what is with in the quotes? [video="123456" align="left"/] ...

PHP & Apache - parse mod_rewrite url

Hi, I have my server's apache configured to redirect every request into index.php, so that I can use urls like : http://www.website.com/about/us Now I need to parse the url in order to determine if each route exists and what to expect from it, so I can set a database table to save the routes and so my clients can edit their routes as...

PHP: Simple regular expressions to match length?

I'm creating a registration system that needs to check the name/pass etc. with REGEX (and prefer to), what I've got so far is: //Check so numbers aren't first, such as 00foobar preg_match('/^(?!\d)[a-z0-9]+$/iD',$usrname); //Just simple check preg_match('/^[a-zA-Z0-9]+$/',$psword); But I have to do stupid things in IF statements like:...

PHP - preg_match?

I'm not very good with expressions... I've looked at some online tutorials, but I'm still not getting it. Basically, I'm trying to return TRUE if a string is formatted like this: 4 digits + space + 2 digits and convert it to a date. So, the string will look like: 2010 02, and I'm trying to output February, 2010. I'm trying to use p...

Reg exp for youtube link

In a system that I'm developing I need to recognize the youtube link in the following format [youtube]youtube url[/youtube] for the moment I arrived at this regular expression: #\[youtube\]http://www.youtube\.(.*)/watch\?v=([a-zA-Z0-9_-]*)\[\/youtube\]#s But this pattern isn't able to recognize url like [youtube]http://www.y...

PHP Regex to grab {tag}something{/tag}

Howdy, I'm trying to come=up with a regex string to use with the PHP preg functions (preg_match, etc.) and am stumped on this: How do you match this string?: {area-1}some text and maybe a <a href="http://google.com"&gt;link&lt;/a&gt;.{/area-1} I want to replace it with a different string using preg_replace. So far I've been able to...

Having a problem matching a html element using Preg_Match

Hello all, I am trying to match a html element but I don't think its matching since $titles is empty - can anyone correct me? My preg_match: preg_match_all("~<td align=\"left\" width=\"50%\">[^<]*. <b><a href=\"(.*?)\">[^<]*</a>~i", $main, $titles); Example HTML to match: //<td align="left" width="50%">1. <b><a title="Wat" href=...

Preg_match - retrieving href

Hello all, I have got stuck with a question I have just been helped on - its a new problem but only just slightly. I have this preg_match to get the contents of href. Please don't tell me not to use regex - I am aware of using other parsers/classes etc but this is an old script that just needs to be fixed for now. :) No time for re-wri...

Get more backreferences from regexp than parenthesis

Ok this is really difficult to explain in English, so I'll just give an example. I am going to have strings in the following format: key-value;key1-value;key2-... and I need to extract the data to be an array array('key'=>'value','key1'=>'value1', ... ) I was planning to use regexp to achieve (most of) this functionality, and wrot...

help with regex -- require AM/PM substring at end

I'm using php's preg_match to get a named subgroups from a string. I'm parsing user-generated date/time strings into well-formatted date/time tokens. Here's my regex ~(?P<month>\d?\d)(/|-)(?P<day>\d?\d)(/|-)(?P<year>\d\d\d?\d?) +(?P<time>[\d: +((A|a)|(P|p))(M|m)]+)~i And it correctly parses dates like 01-17-10 09:30 pm 2/1/2010 06...

query check if its latitude or just text on map

on search i want to check if query is latitude and longitude or just text search with php. $query = '-122.0307642, 37.3316930'; latitude and longitude can have '-' in them also. what preg_match pattern it will be for this? ...

Need a reg-ex to match a length in mm

Im using PHP preg_match() method. I am having trouble with a regular expression to match a mm length. The numeerical length can be a float...here are some exmaples of the data I am working on; 1.0mm 25.5mm 3mm 3 mm 3.3 mm So bacially any integer or float proceeded by "mm" with or without whitespace between. Thanks! ...

Get content from string in different situations

Hi, I'm thinking of storing data from a form as a string, each answer separated by a pipe. The problem I have is that some answers may come in the form of multiple items. We store the radio button selection along with their corresponding answers e.g. Question 1 - 1 Answer [A1] Question 2 - Radio button selected [A2] + 3 form fields Que...

Regular Expression Help, simple string pattern

Hey Guys, I'm having problems creating a regular expression which will fix a valid string. The string will be in the format: any alpha-numerical character 3 to 5 times, followed by a comma if there are more characters after else its the end of the string Example Strings: A401,CR56,4U9Y,MO16,ECZGB,A7DC,9LN5,D52PU,UT95,YBPB0,2JWA,AAMW,K...

Need help with a PHP preg_match

I'm not very good with preg_match so please forgive me if this is easy. So far I have... preg_match("/".$clear_user."\/[0-9]{10}/", $old_data, $matches) The thing I'm trying to match looks like.. :userid/time() Right now, the preg_match would have a problem with 22/1266978013 and 2/1266978013. I need to figure out how to match the...

PHP preg_match help please. Pretty simple

Hi , How do I add into the list of items allowed (gif$|jpg$|png$|jpeg$) into the following code $regexp = "/[0-9a-zA-z\.]/"; if (preg_match($regexp, $imageInput)) also how do I add in an exclude list e.g so stop people unploading .exe files etc. Thanks EDIT I fixed it with the following code any advice on how to make it better ...

php security question

Hi, It has a been a long day but I cannot seem to choose in my own head which is better or if I should use both. Basically what should I use to sanitize user inputted values. Is it either the htmlentities or preg_match function ? I will then if the value goes into a sql query use the mysql_real_escape_string function but only until I...