PHP - Problem With For Each Statement Used With Preg Match
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!!! Similar Tutorialsso 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 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! 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 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 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326673.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})*)?$/'; This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=345772.0 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 ''; } 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 Hi, I am having a pretty difficult time getting files to upload to my server that have a Single Quote in the file name. Example: myfile's.pdf I need to strip the file name of the quote before it uploads to the server. I currently am using SWFUpload and this is the bit of code that was included with it. I need to modify it to remove the single quotes as well. Been hammering my head over this all day. $file_name = preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name'])); if (strlen($file_name) == 0 || strlen($file_name) > $MAX_FILENAME_LENGTH) { HandleError("Invalid file name"); exit(0); } thanks Hello,
I have problem durring binding update query. I can't find what is causing problem.
public function Update(Entry $e) { try { $query = "update entry set string = $e->string,delimiter=$e->delimiter where entryid= $e->id"; $stmt = $this->db->mysqli->prepare($query); $stmt->bind_param('ssi',$e->string,$e->delimiter,$e->id); $stmt->close(); } catch(Exception $ex) { print 'Error: ' .$ex->getMessage(); } }When I run function update I'm getting next error:Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Can you help me to solve this problem ? Edited by danchi, 17 October 2014 - 10:25 AM. My code is as follows <?php // Include the Sessions options require_once('inc/session_admin.inc.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Change Record form</title> <style type="text/css"> td {font-family: tahoma, arial, verdana; font-size: 10pt } </style> </head> <body bgcolor="#64b1ff"> <div align="center"> <?php echo '<p>Hello <b>' .($_SESSION['username']) .'</b> <a href="logging_out.php">Logout</a></p>'; $Username=$_POST['Username']; if ($Username = $Username) { // Include connecting to the database require_once('inc/connect_to_users_db.inc.php'); $query=" SELECT * FROM userinfo WHERE Username='$Username'"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $FirstName=mysql_result($result,$i,"FirstName"); $LastName=mysql_result($result,$i,"LastName"); $Address1=mysql_result($result,$i,"Address1"); $Address2=mysql_result($result,$i,"Address2"); $Address2=mysql_result($result,$i,"Address2"); $Address3=mysql_result($result,$i,"Address3"); $Gender=mysql_result($result,$i,"Gender"); $Country=mysql_result($result,$i,"Country"); $MobileNumber=mysql_result($result,$i,"MobileNumber"); $EmailAddress=mysql_result($result,$i,"EmailAddress"); ?> <table width="300" cellpadding="5" cellspacing="0" border="1"> <tr align="center" valign="top"> <td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff"> <h3>Edit and Submit</h3> <form method="post" action="update_a_user_script.php"> <input type="hidden" name="update_a_user_script" value="<?php echo "$Username" ?>" /> <table cellpadding="0" cellspacing="0" border="0"> <tr align="center" valign="top"> <td>Username:</td> <td><input type="text" name="Username" readonly="readonly" value="<?php echo "$Username" ?>" /></td> </tr> <tr align="center" valign="top"> <td>First Name:</td> <td><input type="text" name="FirstName" value="<?php echo "$FirstName" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Last Name:</td> <td><input type="text" name="LastName" value="<?php echo "$LastName" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Address:</td> <td><input type="text" name="Address1" value="<?php echo "$Address1" ?>" /></td> </tr> <tr align="center" valign="top"> <td> </td> <td><input type="text" name="Address2" value="<?php echo "$Address2" ?>" /></td> </tr> <tr align="center" valign="top"> <td> </td> <td><input type="text" name="Address3" value="<?php echo "$Address3" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Gender:</td> <td><input type="text" name="Gender" value="<?php echo "$Gender" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Country:</td> <td><input type="text" name="Country" value="<?php echo "$Country" ?>" /></td> </tr> <tr align="center" valign="top"> <td>MobileNumber:</td> <td><input type="text" name="MobileNumber" value="<?php echo "$MobileNumber" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Email Address:</td> <td><input type="text" name="EmailAddress" value="<?php echo "$EmailAddress" ?>" /></td> </tr> </table> <input type="submit" value="Update" /> </form> <form method="post" action="update_a_user_form.php"> <input type="submit" value="Update a Different Record" /> </form> <form method="post" action="display_users.php"> <input type="submit" value="List all users" /> </form> <form method="post" action="index.php"> <input type="submit" value="Administrator Interface" /> </form> </td></tr></table> <?php ++$i; } ?> <?php } else { echo 'Username not found!. Please try again'; ?> <table width="300" cellpadding="5" cellspacing="0" border="2"> <tr align="center" valign="top"> <td align="left" colspan="1" rowspan="1" bgcolor="#64b1ff"> <h3>Insert Username</h3> <form method="post" action="update_a_user_form2.php"> Enter Username: <input type="text" name="Username" size="30" /><br /> <br /> <input type="submit" value="Submit" /><input type="reset" /> </form> <form method="post" action="index.php"> <input type="submit" value="Administrator Interface" /> </form> </td> </tr> </table> <?php } ?> </div> </body> </html> It will display what it's meant to display if I have a username that is in the database, however if the username doesn't exist in the database, it's meant to say "Username not found!. Please try again" and show the search box again. However if I put in a Username that doesn't exist. I get a blank page (well at the top of the page the page I do get Hello Howlin1 Logout) What am I doing wrong? Well I guess I'll jump right into the code.. The function: function isIpaddr ($ipaddr) { if (ereg("^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$", $ipaddr, $digit)) { if (($digit[1] <= 255) && ($digit[2] <= 255) && ($digit[3] <= 255) && ($digit[4] <= 255)) { return TRUE; } } return FALSE; } The loop and IF statement: if($_POST['submit_multiple']) { $SubmittedIPs = split("[\n|\r|,|-]", $_POST['IPAddresses']); foreach($SubmittedIPs as $IP) { trim($IP); if(isIpaddr($IP)) { echo $IP." = ".gethostbyaddr($IP)."<br />"; } else { echo "Invalid IP Address<br />"; } } } There's my relevant code.. Now the only problem so far is that I am getting this: Quote 12.34.56.78 = 12-34-56-78.test.hostname.com Invalid IP Address 12.34.56.78 = 12-34-56-78.test.hostname.com Invalid IP Address 12.34.56.78 = 12-34-56-78.test.hostname.com (The IPs and Hostnames are obviously fake..) The problem is that they are valid IP addresses and I've done a few checks to see what's wrong. I've checked the array and it is working fine by splitting up a textbox into an array of IPs and the IPs are fine inside the array. I then tested the script by echoing the output of just the function with each IP, I got all "1"s (TRUE). I just can't figure out why it's displaying both parts of the if statement.. Thanks for any help! So basically I've been experimenting with setting cookies and sessions. The code in my header file will display a login if there is no $_SESSION['username']. However, the else statement verifies that there is, and echo's "hello." My problem lies in the else statement, when the login form disappears, but nothing in the else statement appears. Here's the code, I feel like I am missing something obvious. Code: [Select] <?php if (!isset($_SESSION['username'])){ echo "<li><a href='register.php'>Register</a></li>"; echo "</ul>"; echo " <table> <tr> <form name='login' method='post' action='login.php'> <tr><td>Username</td> <td><input type='text' name='username'></td></tr> <tr><td>Password</td> <td><input type='password' name='password'></td></tr> <tr><td><input type='submit' name='submit' value='Login'></td></tr> <tr><td><input type='checkbox' name='rememberme' value='remember'> Remember</td></tr> </form> </table> "; }else{ echo "hello"; } ?> Thanks in advance I am creating a class alumni web and ask a question tha requires selecting one of 3 radio buttons. If the user selects the 3rd button, I want to display an additional field. Here is the lines of code: <label>Are you or your spouse a Taft Class of 1965 alumni?</label> <input type="radio" id="alumni" value=1 checked><label>yes</label> <input type="radio" id="alumni" value=2><label>no</label> <br> <label>Are you a graduate of Taft Union High School?</label> <input type="radio" id="alumni" value=3><label>yes</label> Error ---> <?php // If alumni is equal to 3 display the input field If ($ans == 3);{ Echo "<input type='int' id='gradClass' size='4' maxlenght='4' placeholder='1977'>" } ?> <br> <hr> <br> <span class="subheader">PRIVACY</span> <br> And I didn't forget a ' this time. Could someone please assist. Thanks in advance. |