PHP - Preg Match Email
Hi all
I am trying to do an email validation check. Here's my code: if (!preg_match($email) == "^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]") { include("checkout-email-error.php"); exit; } It doesn't seem to allow any email addresses through? All help greatly appreciated! Thanks Pete Similar TutorialsHello, I am trying to crawl a website and get all the domain names listed on the site to output into my php script. I am using the following code.... The main area is the preg match area, since I know nothing about it, nor do I understand it a little bit! $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://link I am getting data from.com); curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result=curl_exec ($ch); curl_close ($ch); // Search The Results From The Starting Site if( $result ) { // LOOKING FOR ANYTHING.COM all .com's preg_match_all( "(.*)\.com", $result, $output, PREG_SET_ORDER ); foreach( $output as $item ) { // ALL LINKS DISPLAY HERE print_r($item); } } Any help would be greatly appreciated! so I use file_get_contents to get the contents of a webpage, one of the lines has Code: [Select] <meta property="og:url" content="http://www.google.com/blahblahblah?s=5cd04d4a7632296b9cdb463d04e82c05" /> I want it to echo only http://www.google.com/blahblahblah so anything between <meta property="og:url" content=" and ?s=5cd04d4a7632296b9cdb463d04e82c05" /> I want to extract and put into a variable this works just fine but I was thinking preg match would be better $thread = explode('<meta property="og:url" content="', $psuc); $thread = explode('?s=', $thread[1]); echo $thread[0]; Thanks Hello, I am trying to replace a url and add a sub-id to it, however I'm not quite there. Any help is always appreciated here. In the end, I would like the value of gotoUrl to have the cpId 123abc45 attached to it.
I.E.
http://example.com/?Aff=56732&SID=123abc45 http://example.com/?Aff=56732&uv=123abc45&product=1834234 http://example.com/?Aff=56732&cid=123abc45&ace=2gs244s3 $gotoUrl = "http://example.com/?Aff=56732&SID="; // OR could be listed as such: // $gotoUrl = "http://example.com/?Aff=56732&uv=default&product=1834234"; // $gotoUrl = "http://example.com/?Aff=56732&cid=&ace=2gs244s3"; // Will attach this to replace value $cpId = "123abc45"; // Possible sid replacements, depending on the url $sidList = array("sid","SID","cid","uv"); if ($gotoUrl){ foreach($sidList as $sidVar){ if (preg_match("/$sidVar/i", $gotoUrl)){ $gotoUrl = preg_replace("#{$sidVar}(?=.*\d)(?=.*[a-z])(?=.*[A-Z])$#", "{$sidVar}={$cpId}", $gotoUrl); } } echo $gotoUrl; } Edited by iwpg, 13 August 2014 - 10:36 PM. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=331482.0 hey, i was wondering how i would make a preg match check for special characters, i would only like to allow an underscore _ and a dash - i'm currently using preg_match("/[^0-9]+$/",$getUser) but thats not working right How do I fix this For Each statement when used with preg match? //Cat_ID & Category Name preg_match_all('%<a[^href=]*href=\"\/cats\.asp\?cat_id=(.*?)\" title="(.*?)">%',$data,$matches1,PREG_SET_ORDER); // works fine preg_match_all('%/60/(.*?).jpg"%s',$data,$matches2,PREG_SET_ORDER); // works fine preg_match_all('%h3><p>(.*?)<\/p>%s',$data,$matches3,PREG_SET_ORDER); // works fine foreach ($matches1 as $val) { //need help here $subcat_id=$val[0][1]; $subcat=$val[0][2]; $cat_image=$val[1][1]; $cat_desc=$val[2][1]; Thanks for your help!!! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326673.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=345772.0 Hi all I'm quite a competent PHP coder but where it comes to preg_match I prefer to be ignorant, because I can't get my head around the patterns. Basically, I'm working with a script that someone else has written, and I'm coming across problems because the URL that is being validated sometimes has curly brackets '( )' in it (these are image file names generated by an internal system). I have the pattern, how do I modify this to allow curly brackets? On some occasions, the urls have just the opening or just the closing, so its never the complete set. if someone could give me an indication with this, because I'm clueless! Thanks in advance! Ste pattern: Code: [Select] $pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/'; Hi All, I am trying to create a PHP code that will run a form, however i keep getting the error message Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in D:\xampp\htdocs\HFCC\Scripts\mailprocess.php on line 55 Invalid email address entered. Go Back and try again attached is the complete copy of the code i am using, i have an email text box and label with the id 'email' also my method is POST and my action is Scripts/mailprocess.php. Please let me know if you need any additional details. Any help will be much appreciated. Thanks Please help me with this code. It keep appear in my website. "Warning: preg_match() [function.preg-match]: No ending delimiter '.' found in /home/kengsite/public_html/wp-content/plugins/statpress/statpress.php on line 1184" And this is how the line look like. if (!preg_match(".ico$", $urlRequested)) { return ''; } i use a user management system which can be download this from http://rapidshare.com/files/39584153...LL-DGT.zip.rar i also have a script which emails a link to the entered email address.... i want it to check if the entered email matches with the logged in users email on the database..... this email script can be downloaded from http://rapidbay.net/download/1364276...kurl-v1-7.html as im totally new to php i wud appriciate if u cud explain a lil bit.. pls help.... Hi, I want to separate out the file name from an image url. Not sure the best way to do it? I want to basically select all text after the last / slash. eg - image.jpg would be the result from http://www.google.com/images/image.jpg What's the best way to do it? Cheers Rob i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers $name = preg_replace('{(\d+)}', convertNumber("$1"), $row['name']); why isnt this working? Hello, I come from a C and PERL background. I seem to have trouble finding how to do this easily. What is the PERL equivalent of: $var =~ s/^\+//g; // remove a plus from the beginning, and from the entire string. Thanks. basically what i am trying to do is replace the <a href="whatever.com"> with <a href="whatever.com" onclick = "if (! confirm("Continue?")) return false;"> so that when the user clicks the url in a message the box pops up first then redirects them to the url if they click confirm. However i am getting the following error: Code: [Select] Warning: preg_replace() [function.preg-replace]: Compilation failed: reference to non-existent subpattern at offset 11 here is the code i used. $message_content = $content_info['message_content']; $pattern='<a href="\\1">'; $replace='<a href="\\1" onclick = "if (! confirm("Continue?")) return false;">'; $message_content = preg_replace($pattern, $replace, $message_content); echo $message_content; Anyone know where i went wrong? This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=311437.0 im having trouble using this function. im trying to change the strings within a post. eg: Code: [Select] This is an example post [attachment=file.png] what im trying to do is change [attachment=file.png] to file.png. Here is the code i have but it doesnt change anything. $p_content = str_replace('<br>', '', $post_info[$key]['p_content']); $attach = preg_split('|\[attachment=|', $p_content); for($i=0; $i<count($attach); $i++) { $attach[$i] = str_replace(']', '', $attach[$i]); if(file_exists($config['asf_root'].'attachments/'.$attach[$i])) { $p_content = preg_replace('|\[attachment=([0-9a-zA-Z\.-_])\]|#i', $attach[$i], $p_content); } } echo $p_content; it first gets all the attachment tags within the post then applies the preg replace to all of them. But the preg replace isnt replacing, so i must have gone wrong somewhere. Any tips/ideas? Thanks This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=310802.0 |