PHP - Trouble Submitting (preg_match)
Hello folks,
I am busy with some code that is handled with preg_match. When a certain kind of text is enter and recognized the next box is highlighted for input. Once all input is recognized you are able to press the Send button. All works. Expect for one thing. When the first textbox start with a 2, it is recognized, but it is not coupled to the last textbox. Which holds the form from being submitted. How can i make sure that when a certain textbox input starts with a 2, the preg_match should be ignored? Cheers! <html> <head> <link REL=StyleSheet HREF="css/style.css" TYPE="text/css" MEDIA=screen /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script type="text/javascript" src="css/fancybox/jquery.fancybox-1.3.4.pack.js"></script> <link rel="stylesheet" href="css/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" /> </head> <body onload="document.barcodefrm.barcode.focus()"> <div id='wrapper'> <img class='bird' src='css/bird.png' alt="Logo" /> <img class='logo' src='css/logo.gif' alt="Logo" /> <br><H1> Please book all items you use by scanning the barcodes<br> and press Send to store when all fields are filled correctly.</H1> <br> <div id ='content'> <div id='contentwrapper'> <?php session_start(); if ($_GET['reset']=="true") { session_destroy(); Header("location: scanform.php"); } include("functions.php"); function check_form_input($array) { if (isset($array['wo']) AND isset($array['user']) AND isset($array['plane']) AND isset($array['qty']) AND isset($array['part']) ) { return true; } else { return false; } } if (isset($_POST['barcode'])) { echo 'Barcode scanned: '; $barcode = $_POST['barcode']; if (substr($barcode,0,2)=="RO" or substr($barcode,0,2)=="RD") { echo "Partnumber."; /* hier nog de query bakken voor amos */ $_SESSION['form']['part']=getpartnumber($barcode); } elseif (preg_match( '/^WO[0-9]{7}(?:-[0-9]{2})?/', $barcode)) { echo "Workorder number."; $_SESSION['form']['wo']=getworkorder($barcode); } elseif (preg_match( '/^SG\.[A-Z]{5,6}$/', $barcode)) { echo "Nayak user sign."; $_SESSION['form']['user']=substr($barcode,3,999); } elseif (preg_match( '/^AC\.[A-Z]{3,4}$/', $barcode)) { echo "Aircraft."; $_SESSION['form']['plane']=substr($barcode,3,999); } elseif (preg_match( '/^[0-9]{1,2}$/', $barcode)) { echo "Quantity."; $_SESSION['form']['qty']=$barcode; } else { echo "This is not a valid barcode."; } } ?> <form name="barcodefrm" id="barcodefrm" method="post" action="scanform.php?reset=false"> <div class="form-row"><span class="label">Scan barcode:</span> <input type="text" name="barcode" id="barcode"></div> <div class="form-row"><span class="label"> </span> <!--<input type="submit" class='send' value='Reset'>--> </div> </form> <form id="form1" method="post" action="scanform.php"> <div class="form-row"><span class="label">Workorder: </span><input type="text" name="wo" value="<?= $_SESSION['form']['wo']; ?>"></div> <div class="form-row"><span class="label">User sign: </span><input type="text" name="user" value="<?= $_SESSION['form']['user']; ?>"></div> <div class="form-row"><span class="label">Part: </span><input type="text" name="part" value="<?= $_SESSION['form']['part']; ?>"></div> <div class="form-row"><span class="label">Location: </span><input type="text" name="location" value="<?= $_SESSION['form']['location']; ?>"></div> <div class="form-row"><span class="label">Quantity: </span><input type="text" name="qty" value="<?= $_SESSION['form']['qty']; ?>"></div> <div class="form-row"><span class="label">Aircraft: </span><input type="text" name="plane" value="<?= $_SESSION['form']['plane']; ?>"></div> <div class="form-row"><input class="submit" type="submit" name="submit" value="Send to store" class='sendbutton' <?php if (!check_form_input($_SESSION['form'])) { echo "disabled"; } ?>></div> </form> <input type="submit" class='send' value='Reset values' onclick="location.href = '?reset=true'"> <pre> <?php //print_r($_SESSION['form']); ?> </pre> </div> </div> </div> <script type="text/javascript"> $("#form1").bind("submit", function() { $.fancybox.showActivity(); $.ajax({ type : "POST", cache : false, url : "saveform.php", data : $(this).serializeArray(), success : function(data) { $.fancybox(data, { 'onClosed' : function() { location.href='?reset=<?= ($debug ? "false" : "true"); ?>'; } }); } }); //location.href='?reset.true'; return false; }); </script> </body> </html> Similar TutorialsThis topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=330011.0 in my site search some of the results come out still with html. i have used the strip tags function but how would i use the preg_match function to get rid of the "> still left over? I have a DOMDocument which I inspect an HTML page for links (href) That part works however I am not sure how to use preg_match if I only want to display a link in this layout: <tr> <td headers="c1"><a title="Link to entity information." tabindex="1" href="CORPSEARCH.ENTITY_INFORMATION?p_nameid=3236937&p_corpid=3227476&p_entity_name=%41%72%77%65%6E%20%45%71%75%69%74%69%65%73&p_name_type=%41&p_search_type=%42%45%47%49%4E%53&p_srch_results_page=0">ABC LLC</a></td> </tr> I hope someone is really good at preg_match to help me. Thanks. I need to select an array item based on my preg result. for example: Code: [Select] $content = 'test-1'; $match = preg_replace('|test-([0-9])|', $array['\\1'], $content); is this possible? Hi guys, I have been using this code: preg_match('/<h2>(.*?)<\/h2>/', $data, $matches); which i changed to: $tag1 = 'h2'; $tag2 = 'h2'; preg_match('/$tag1(.*?)$tag2/', $data, $matches); however i need it to work allowing variables (of any character or symbol) within $tag1. I tried $tag1 = 'h(.*?)2'; $tag2 = 'h2'; preg_match('/$tag1(.*?)$tag2/', $data, $matches); but that does not work .... essentiall the whole thing would work like this (example only): firstpartoftag1VARIABLE1lastpartoftag1VARIABLE2tag2 ps the preg_match should only capture the VARIABLE2 data not VARIABLE1 any ideas or help would be much appreciated cheers in advance I'm pretty new to this, How exactly could i get the text between the www. and .com? so if i have a url: http://www.facebook.com I want to just return "facebook" im trying to make a script so i can get users details like longitude, latitude etc
but im having trouble matching the html by regular expression
here is the html below that im trying to extract the data from:
any help or possible any alternative, suggested ways would be greatful thank you
<td>Country:</td> <td><img src="/images/dot.gif" class="flag-16 gb" align="absmiddle" width="16" height="16" title="United Kingdom"> United Kingdom (GB)</td> </tr> <tr> <td>City:</td> <td>Newport</td> </tr> <tr> <td>Region:</td> <td>Newport</td> </tr> <tr> <td>Latitude:</td> <td>51.5833</td> </tr> <tr> <td>Longitude:</td> <td>-2.9833</td> </tr> <tr> <td>Timezone:</td> <td>Europe/London</td> <?php $url = "http://smart-ip.net/geoip/2.101.108.124/"; $ch = curl_init(); $timeout = 0; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $rawdata = curl_exec($ch); curl_close($ch); if (preg_match('/<td>Country:</td><td>[img](?P<country>\w+)</td>/$', $rawdata, $match)) { $country = $match['country']; } if (preg_match('/<td>City:</td><td>(?P<city>\w+)</td>/$', $rawdata, $match)) { $city = $match['city']; } if (preg_match('/<td>Region:</td><td>(?P<region>\w+)</td>/$', $rawdata, $match)) { $region = $match['region']; } if (preg_match('/<td>Latitude:</td><td>(?P<latitude>\d+)</td>/$', $rawdata, $match)) { $latitude = $match['latitude']; } if (preg_match('/<td>Longitude:</td><td>(?P<longitude>\d+)</td>/$', $rawdata, $match)) { $longitude = $match['longitude']; } if (preg_match('/<td>Timezone:</td><td>(?P<timezone>\w+)</td>/$', $rawdata, $match)) { $timezone = $match['timezone']; } ?> information.txt <li><img src="http://www.lol.com" alt="0" /></li> <li><img src="http://www.lol.com" alt="1" /></li> <li><img src="http://www.lol.com" alt="4" /></li> <li><img src="http://www.lol.com" alt="9" /></li> <li><img src="http://www.lol.com" alt="1" /></li> <li><img src="http://www.lol.com" alt="7" /></li> <li><img src="http://www.lol.com" alt="2" /></li> How can I get the alt="$ValueIwant" for each with a preg_match How to a check if a php variable value is one of the following characters: A to J, or ,k to t, (ie.: A B C D E F G H I J k l m n o p q r s t)
I tried:
if (preg_match[A-Jk-t], $checkChar) { // do this } Hi, I have the following code which FTPs to a site, gets the source code for a HTML file and then puts the data inbetween <TITLE> and </TITLE> into an array and this works fine: <?php $file = file_get_contents("ftp://user:pass@domain/public_html/index.html", "r"); if (!$file) { echo "<p>Unable to open remote file.\n"; exit; } preg_match_all ('/<TITLE>(.*)<\/TITLE>/msU', $file, $matches, PREG_SET_ORDER); print_r ($matches); ?> Rather than finding a match for data between <TITLE> and </TITLE> however I would like it to pull back what is inbetween the following: <!--START--> and <!--END--> I have tried the following but it doesn't put anything into the array: preg_match_all ('/<!--START-->(.*)<\/!--END-->/msU', $file, $matches, PREG_SET_ORDER); This is the content of the html file if this helps: Code: [Select] <TITLE>The Title</TITLE> <!--START--><p><strong>Some Text</strong></p> <p><strong><img src="images/IMAG0152_2.jpg" alt="" width="200" height="100" /></strong></p> <!--END--> i can get a match on stuff between TITLEs but not START and END.. I'm not sure how to change preg_match_all to work!! i've tried loads of combinations but can't get any to work, but i'm not really sure on modifiers and patterns or escaping etc, if anyone could help that would be great. Thanks in advance kev. Hi,
I don't know much about php. Recently my host updated php version to 5.4 and i function eregi() is deprecated errors, so after some googling, replaced it with preg_match but i am stuck with errors
Code:
preg_match("^ and", "", $mid_str)
Error: Warning: preg_match(): No ending delimiter '^' found
Tried the following method but not working
preg_match("/^ and/", "", $mid_str)
Can you guys help me with correct code?
Thanks for looking.
I know $regex_pattern is wrong but I need a solution to find a content between <body> and </body>. Code: [Select] <?php $content = "<html><head><title>Your IP</title></head><body>Your IP Address: 63.1.142.154</body></html>"; $regex_pattern = "/<body>(.*)<\/body>/"; $preg_match($regex_pattern,htmlspecialchars($content),$matches); print_r( $matches ); ?> Hi,
I have a "scraped" string and want to use the preg_match() to give me just a pice of it.
The string is from a webpage, but is dynamic....
here´s the typical string format:
<a class="stripped-link lightblue-link profile-page-link" href="/x/xxx+xxx+xxx/xxxx">HER IS THE WANTED TEXT</a>
The orange is static. The green (the xxxx is the dynamic part of the string)
Can I use the preg_match() for this?
thanks (and yes I´m a newbe.... )
Hey guys, In my contact form i have the action: preg_match but i've come accross a problem. Problem: Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\Program Files (x86)\wamp\www\ts\contact.php on line 34 Code:$error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; Thanks in advance Hi im trying to do a registration form and i am new to using preg_match. I keep getting the error "( ! ) Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\wamp\www\registration1.php on line 67" and for every other line I use preg_match. this is an example of how i have used it Code: [Select] if ( preg_match('^[[:alnum:]\.\'\-]{4,50}$', stripslashes(trim($_POST['UserName']))) ) { $UserName = mysql_real_escape_string($_POST['UserName']); $query = "SELECT UserName FROM Users WHERE UserName = '$UserName'"; $result = @mysql_query($query); $num = @mysql_num_rows($result); im such a noob at this can someone please help me I would also like to add that I have read the http://www.php.net/manual/en/function.preg-match.php page but i dont really understand it. Im trying to match this string, but i dont wat to match normal words like "hello world 646" Code: [Select] $string = "2ab055843241f20044af82ae0d5ace04"; //always over 15 chars - without spaces if ( preg_match('~^[0-9\s]+$~D', $string)) { echo 'yes'; } If i can do it with preg_match that would be great Why dosent this work, im trying to match upper case, lower case and numbers only Code: [Select] $id = '3xDJ7@#'; if (!preg_match('/^[a-zA-Z0-9]/', $id)){ echo "ERROR!"; }else{ echo 'ok'; } This always echos "ok" I've tried alot of different ways, google, but just can't find the correct way to do this.. I'm trying to search for a word in an inputted string.. here's the code <html> <head><title>TESTING</title></head> <body> <form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"/> email: <input type=text name=email value="" /><br/> feedback: <input type=text name=ex value=""/><br/> <input type="submit" value="submit" /><br/> </body> </html> <?php $email = $_GET['email']; $ex = $_GET['ex']; $pattern = '/^[a-zA-Z0-9\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z]+$/'; //$pattern1 = '/nprezident/prezident/'; if(!preg_match($pattern, $email)){ echo 'invalid email address<br/>'; } else { echo 'good to go<br/>'; } if(preg_match('/nprezident/,/prezident/', $ex)){ echo 'just something about that sentence is nice'; } else { echo 'no good'; } ?> Ok the one I'm having a problem with is the second preg_match when trying to search for two words i can get one word to print but when i use add a second word it gives an error. How do i add a second word? i'm trying to grab the file name from mediafire to my database caption, I have rapidshare working fine. here's the code for rapidshare Code: [Select] if($type==1) { $words=$links[$j]; preg_match("/rapidshare\.com\/files\/\d+\/(.+)/",$words,$match); unset($words); $words=$match[1]; unset($match); $words=preg_split("/[_\.\-]/",$words); $lastword=array_pop($words); if($lastword=="html") array_pop($words); $words=implode(" ",$words); $words=preg_replace("/\s{2,}/"," ",$words); $caption=mysql_real_escape_string($words); unset($words); }How ever, i'm not sure which preg_match would be the correct one for mediafire.. appreciate any help. Hey guys,
I am stuck on this preg_match if statement. I want to allow ' and " in the variable string but for some reason it keeps reporting invalid characters when I add ' or " to the string.
Any help would be appreciated as I have tried tons of combinations after searching google.
Thanks!
if(preg_match("/[^a-zA-Z0-9\-\_\,\!\?\.\'\"\ \/]+/i",$_POST['article_title'])) { $err[]='<p class="error" style="color: #ed1c24;">Your Title contains invalid characters!</p>'; } |