Preg match and replace for img urls Programming Web Development by ade92uk I have used preg match to find in a page all img tags: [CODE]<(… help with preg match Programming Web Development by realnsleo hi...i want to use the preg match function to verify a string that should have the format format of a year - two digits - two letters - two digits, like this: [in]2005-03-IT-031[/in] thanks possible to layer preg match? Programming Web Development by andrewliu …;/div>[/CODE] This is where I have the first preg match to get this div tag. Then I wanted to obtain… Re: possible to layer preg match? Programming Web Development by smantscheff It is not clear which part you want eventually to match. Do you want to replace css classes? The first three preg_match statements are better put in one single statement to clarify the code. But first tell us which part you want to have extracted. Re: Preg match and replace for img urls Programming Web Development by jrdark13 I don't know about the other stuff but I know for a fact your second code didn't work be cause [inlinecode]if ($urlres = true) {[/inlinecode] should be [inlinecode]if ($urlres == true) {[/inlinecode] instead. Oh, and why are you using #? Re: Preg match and replace for img urls Programming Web Development by jrdark13 here is something I found for you, It's a start but not complete: [CODE] $site = "http://example.com/images/"; $image = preg_replace('/<img src='(.*)([\/])(.*)' \/>/i', '".$site."$3', '<img src='../../../pic.gif' />'); //$image will return http://example.com/images/pic.gif [/CODE] $site has to be … Re: preg match getting contents in div tags in div tags Programming Web Development by smantscheff Regular expressions do not work recursively. To match arbitrarily deeply nested div tags you would need such an recursion. You could use a regex for this special case like this: [CODE] preg_match_all('~<div class=\'name\'>\s*(<div.*?</div>\s*)?(.*?)</div>~is', $res, $matches );[/CODE] Search for an exact match Programming Web Development by tulipputih Hello, anybody can suggest me on how to do exact match in php ( for search purpose). From my reading I understand that we need to use " ". What is the correct syntax for this? Is preg-match important here. Thank you. Re: help with preg match Programming Web Development by azimuth0 Ok, so what is the question? Re: help with preg match Programming Web Development by johny_d [code]<?php $string = '2005-03-IT-31'; if (preg_match ('/^[\d]{4}-[\d]{2}-[a-z]{2}-[\d]{2}$/i',$string)) { echo "Right format"; } else { echo "Wrong format"; } ?>[/code] Re: help with preg match Programming Web Development by azimuth0 That won't work, unless I'm reading it wrong... [code] <?php $string = '2005-03-IT-31'; if (preg_match('/^\\d{4}-\\d{2}-[a-z]{2}-\\d{2}$/i',$string)) { echo "Right format"; } else { echo "Wrong format"; } ?> [/code] Re: help with preg match Programming Web Development by johny_d The way I wrote it [code] ... [\d]{4}... [/code], it works. The way you wrote it [code] ... \\d{4} ... [/code], it doesn't. Re: help with preg match Programming Web Development by realnsleo that worked, thanks alot... Re: help with preg match Programming Web Development by johny_d You're welcome Re: possible to layer preg match? Programming Web Development by andrewliu sorry for the confusion, I wanted to extract titles and thumbs, but im not sure how to put it in 1 foreach and set thumbs and titles in a different variable? Is that possible? Thanks Re: possible to layer preg match? Programming Web Development by smantscheff I assume that with "title" you refer to the contents of the h2 tag. $text = '<div class="dealsListS"> <h2>contents</h2> <div class="thumbWrapper">images</div> </div>'; [CODE]preg_match( '~<div class="dealsListS">\s*<h2>(.*?)</h2>\s*<div class="… Re: possible to layer preg match? Programming Web Development by andrewliu I got it. Thanks. I did two foreach loops and set them into an array and then outputted it out into a single string. preg match Programming Web Development by designingamy Hello all, I am having a hard time trying to figure out why I can't get my code to successfully check my email address. It seems I can plug in anything and it won't give me an error. This is my code for that line: [code] <?php session_start(); if((!empty($_POST['email']) && (preg_match('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $… Re: preg match Programming Web Development by somedude3488 why are comparing the preg_match to "<50". preg_match returns true or false. it will return a matches array that you can get the count of if you are trying to make sure there are not over 50 email addresses in the field, which is probably not what you are trying to do. just remove that and it should work. i didn't check out the rest… Re: preg match Programming Web Development by sikka_varun Hi... Why are u comparing this value with 50.... preg_match returns true of false... If you are comparing with the strlength, then use different if for comparing the string length.. use the following if condition.. this will run... [code=php] if( !empty($_POST['email']) && preg_match('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_POST… Re: preg match Programming Web Development by designingamy Oh, I see. I was trying to control how many characters were entered in the box. Silly me. Thanks everyone! It works now! ~Amy preg match help Programming Web Development by thompson007 I want to check weather or not a string contains (alpha numeric characters and "-") only without spaces and other stuff... *but it must contain atleast one alpha numeric character and a maximum of two "-" example: value could be "-asd-"or "ads-" or "asd7" or "ads or "a-7ds" I … Re: preg match help Programming Web Development by ShawnCplus [code=php]preg_match('/^[\w\-]+$/', $value)[/code] Re: screen scrape and preg match Programming Web Development by digital-ether … from 1 being the first (). $matches[0] contains the whole match. This would be a lot faster with single string functions… Re: screen scrape and preg match Programming Web Development by digital-ether …]$regex = "/(\d+)\s\\$|\\$\s(\d+)/";[/CODE] I will match any string of digits before a space before $. and any… preg match getting contents in div tags in div tags Programming Web Development by andrewliu Hello I'm learning regexp and I'm trying to get contents in a div tag. [CODE]<div class='name'> <div class='contents'> contents </div> </div>[/CODE] my regexp is something like this [CODE] preg_match_all("/\<div class=\"name\"\>(.*?)\<\/div\>/is", $res, $matches );… Re: preg match getting contents in div tags in div tags Programming Web Development by andrewliu what if there were multiple div tags inside the div class='name'? does the [CODE](<div.*?</div>\s*)[/CODE] take care of all that too? Or that only takes care of one div tag nested inside div class='name'? Thank you for your help Re: preg match getting contents in div tags in div tags Programming Web Development by smantscheff [ICODE](<div.*?</div>\s*)[/ICODE] matches until the first [ICODE]</div>[/ICODE]. Therefore you cannot tackle nested divs (or other nested tags) with it. Use a recursive or parse function for that. Re: preg match getting contents in div tags in div tags Programming Web Development by andrewliu Thanks! if there's multiple same div names throughout the page because of a while loop say [CODE][B]<div class='name'>[/B]</div> <div>code here</div> etc.. [B]<div class='name'>[/B]</div> <div>code here</div> etc... [B]<div class='name'></div>[/B] <div>code here</div> etc… Re: preg match getting contents in div tags in div tags Programming Web Development by smantscheff If divs are not nested you get them with the code from your first post (after fixing the quotes): [ICODE]~<div class='name'\>(.*?)</div>~s[/ICODE]