PHP - Moved: Preg_replace Woes
This topic has been moved to PHP Regex.
http://www.phpfreaks.com/forums/index.php?topic=346278.0 Similar TutorialsThis topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=350441.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347057.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=332527.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=330098.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320391.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=306005.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=331361.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347016.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347065.0 So, I'm getting a blank PHP page and it's driving me nuts. Unfortunately the client won't let me post my code up here, but rest assured that I'm an experienced web developer and have checked all of the usual suspects. I enabled error reporting, checked my apache error log, and neither of those produce any messages. The syntax is correct. I tossed in "die('here!')" in a few places until I couldn't see it. I narrowed down the stop point as being somewhere in the middle of a foreach loop. Before this foreach loop, I'm using array_merge on some fairly large pieces of data, but nothing unreasonable. When I comment out the array_merge line, the page works correctly. I figured maybe there was some kind of memory issue, or execution timeout thing going on, but when I increase both of those settings it has no effect. In essence, I'm wondering what might be some causes of the blank page problem beyond the common ones, since I'm really scratching my head over this one. Hi there Got a problem needs a solution, basically a booking system has been built (by me) and works great except for the checking availablity Basically they can do drives in a car (in any order) so I need to try all possible combinations. one idea I had was to use an array holding the availability for each slot so that it looks like slotArray=array("ABC","AC","C","A","BC","AB","ABC" ...etc) looking for drives A and B so check if slotArray[1] contains A and Slot Array 2 contains b or vice versa what i need to do is work out all the possible orders of a string ABCDE (there will be 120 of them) so I can systematically check the order anyone have a function that will do this? Hi Everyone, Please have a look at the code below the first set is from my contact form and the second is the function, it is a function that is passed a form variable in the form of an array and is also passed a form title variable. Everything worked fine this morning but when I checked the functionality of it a few hours ago the mail function wasn't sending, although the logic was working. I checked my spam filter and the emails weren't held up there. Code: [Select] require('../php_classes/TrueViewI.php'); include('../php_functions/functions.php'); if(isset($_POST['submit'])) { $error_message = processFormData($_POST, 'Home Inspections'); if($error_message == 'Thank you, someone will contact you shortly.') { session_unset(); } } //future $keywords = ''; //future $meta_tags = ''; //future $left_column = ''; $middle_column = '<img class="page_heading" src="../images/contactus.png" alt="True View Service Home Inspections Contact Us" /> <form method="post" action=""> <fieldset id="contactform"> <!-- <legend>Home Inspections Contact Form</legend> --> <h4>Home Inspections Contact Form</h4> <span class="errors">'.(!empty($error_message) ? $error_message : '').'</span> <div class="row_div"> <div class="label_div"> <label>First Name:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <input name="First Name" type="text" maxlength="50" size="50" value="'. (!empty($_SESSION['First_Name']) ? $_SESSION['First_Name'] : '').'" /> </div> </div> <div class="row_div"> <div class="label_div"> <label>Last Name:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <input name="Last Name" type="text" maxlength="50" size="50" value="'. (!empty($_SESSION['Last_Name']) ? $_SESSION['Last_Name'] : '').'" /> </div> </div> <div class="row_div"> <div class="label_div"> <label>Phone Number:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <input name="Phone Number" type="text" maxlength="50" size="50" value="'. (!empty($_SESSION['Phone_Number']) ? $_SESSION['Phone_Number'] : '').'" /> </div> </div> <div class="row_div"> <div class="label_div"> <label>Email Address:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <input name="Email Address" type="text" maxlength="50" size="50" value="'. (!empty($_SESSION['Email_Address']) ? $_SESSION['Email_Address'] : '').'" /> </div> </div> <div class="row_div"> <div class="label_div"> <label>Renovation Address:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <input name="Renovation Address" type="text" maxlength="50" size="50" value="'. (!empty($_SESSION['Renovation_Address']) ? $_SESSION['Renovation_Address'] : '').'" /> </div> </div> <div class="row_div"> <div class="label_div"> <label>Age of Home:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <select name="Age Of Home" class="input"> <option value="">--Choose One--</option> <option value="0-10"'. ((!empty($_SESSION['Age_Of_Home']) && ($_SESSION['Age_Of_Home'] == '0-10')) ? ' selected="selected" ' : ''). '>0 to 10 years old</option> <option value="11-20"'. ((!empty($_SESSION['Age_Of_Home']) && ($_SESSION['Age_Of_Home'] == '11-20')) ? ' selected="selected" ' : ''). '>11 to 20 years old</option> <option value="21-30"'. ((!empty($_SESSION['Age_Of_Home']) && ($_SESSION['Age_Of_Home'] == '21-30')) ? ' selected="selected" ' : ''). '>21 to 30 years old</option> <option value="31-40"'. ((!empty($_SESSION['Age_Of_Home']) && ($_SESSION['Age_Of_Home'] == '31-40')) ? ' selected="selected" ' : ''). '>31 to 40 years old</option> <option value="41-50"'. ((!empty($_SESSION['Age_Of_Home']) && ($_SESSION['Age_Of_Home'] == '41-50')) ? ' selected="selected" ' : ''). '>41 to 50 years old</option> <option value="50+"'. ((!empty($_SESSION['Age_Of_Home']) && ($_SESSION['Age_Of_Home'] == '50+')) ? ' selected="selected" ' : ''). '>More than 50 years old</option> </select> </div> </div> <div class="row_div"> <div class="label_div"> <label>Square Footage of Home:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <select name="Square Footage Of Home" class="input"> <option value="">--Choose One--</option> <option value="1000-1500"'. ((!empty($_SESSION['Square_Footage_Of_Home']) && ($_SESSION['Square_Footage_Of_Home'] == '1000-1500')) ? ' selected="selected" ' : ''). '>1000 to 1500 square feet</option> <option value="1501-2000"'. ((!empty($_SESSION['Square_Footage_Of_Home']) && ($_SESSION['Square_Footage_Of_Home'] == '1501-2000')) ? ' selected="selected" ' : ''). '>1501 to 2000 square feet</option> <option value="2001-2500"'. ((!empty($_SESSION['Square_Footage_Of_Home']) && ($_SESSION['Square_Footage_Of_Home'] == '2001-2500')) ? ' selected="selected" ' : ''). '>2001 to 2500 square feet</option> <option value="2501-3000"'. ((!empty($_SESSION['Square_Footage_Of_Home']) && ($_SESSION['Square_Footage_Of_Home'] == '2501-3000')) ? ' selected="selected" ' : ''). '>2501 to 3000 square feet</option> <option value="3000+"'. ((!empty($_SESSION['Square_Footage_Of_Home']) && ($_SESSION['Square_Footage_Of_Home'] == '3000+')) ? ' selected="selected" ' : ''). '>More than 3000 square feet</option> </select> </div> </div> <div class="row_div"> <div class="label_div"> <label>Are you buying or selling?:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <select name="Buying Or Selling" class="input"> <option value="">--Choose One--</option> <option value="Buying"'.((!empty($_SESSION['Buying_Or_Selling']) && ($_SESSION['Buying_Or_Selling'] == 'Buying')) ? ' selected="selected" ' : '').'>Buying</option> <option value="Selling"'.((!empty($_SESSION['Buying_Or_Selling']) && ($_SESSION['Buying_Or_Selling'] == 'Selling')) ? ' selected="selected" ' : '').'>Selling</option> </select> </div> </div> <div class="row_div"> <div class="label_div"> <label>Preferred Date and Time for Inspection:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <input name="Preferred Date and Time for Inspection" type="text" maxlength="50" size="50" value="'. (!empty($_SESSION['Preferred_Date_and_Time_for_Inspection']) ? $_SESSION['Preferred_Date_and_Time_for_Inspection'] : '').'" /> </div> </div> <div class="row_div"> <div class="label_div"> <label>Comments or Questions:</label> <!-- <span class="required">* </span> --> </div> <div class="input_div"> <textarea name="Comments or Questions" type="text" rows="10">'. (!empty($_SESSION['Comments_or_Questions']) ? $_SESSION['Comments_or_Questions'] : '').'</textarea> </div> </div> <div class="row_div"> <input id="button" name="submit" type="submit" value="Send Message" /> </div> </fieldset> </form>'; $contact = new TrueViewI('True View Services Inspections - Contact Us', '../css/styles.css', NULL, NULL, 7, 1, 1); $contact->setContent('middle_col_content', $middle_column); $contact->display_page(); Code: [Select] function processFormData($array, $form) { $errors = NULL; $message = NULL; foreach($array as $key => $value) { //if any of the form values are empty catch them and add to error array if(empty($value) && $key != 'submit') { //build error list $errors .= '"' . str_replace('_', ' ', $key) . '" is a required field!<br />'; } else if(!empty($value) && $key != 'submit') { //capture values and insert them into a session variable $_SESSION[$key] = $value; } } if(empty($errors)) { mail('tinwakr@bell.net', $form, str_replace('_', ' ', $message)); return 'Thank you, someone will contact you shortly.'; } else { return $errors; } } Hi all Basically, I have a form which when done will calculate a quote for turf for given areas. Basically each time the user specifies an area it goes into an array, and they can add as many as they want, but the problem seems to be once submitted and it arrives back into the program, it isn't decoding so the multidimensional array is lost. What am I doing wrong here? Full code below, thanks in advance Ste Code: [Select] <?php // Framework // Get the sections $sections_array = base64_decode(unserialize($_POST['sections'])); // Build the rest of the array foreach ($sections_array as $section) { $sections[] = base64_decode(unserialize($section)); } // Set the initial unit $units = $_POST['units']; // Do the new add if ($_POST['a'] == 'add_section') { // Add the new measure if ((is_numeric($_POST['width'])) && (is_numeric($_POST['length']))) { $sections[] = array('length' => $_POST['length'], 'width' => $_POST['width']); } } // Build the output foreach ($sections as $section) { $output .= '<strong>'.$section['width'].' wide</strong> x <strong>'.$section['length'].' long</strong><br />'; $sections_array = base64_encode(serialize($section)); } ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <style type="text/css"> body,td,th { font-family: Verdana, Geneva, sans-serif; font-size: 11px; } body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } .wrap { text-align: center; height: 350px; width: 410px; padding: 0 10px; } </style> </head> <body> <div class="wrap"> <h2>Turf Calculator</h2> <p>To begin, enter the width and length of the first area of garden you wish to turf. You can keep adding sections to work out the final quantity required.</p> <p><?php echo $output; ?></p> <form id="form1" name="form1" method="post" action=""> <table width="0" border="0" cellspacing="0" cellpadding="2"> <tr> <td>Length:</td> <td><input type="text" name="length" id="length" /></td> </tr> <tr> <td>Width:</td> <td><input type="text" name="width" id="width" /></td> </tr> <?php if ($units == '') { ?> <tr> <td>Units:</td> <td><select name="units" id="units"> <option value="feet">Feet</option> <option value="m" selected="selected">Metres</option> <option value="yards">Yards</option> </select></td> </tr> <?php } ?> </table> <p> <input type="submit" name="add" id="add" value="Add This Section" /> <input name="a" type="hidden" id="a" value="add_section" /> <input name="sections" type="hidden" id="sections" value="<?php echo base64_encode(serialize($sections_array)); ?>" /> <?php if ($units != '') { ?> <input name="units" type="hidden" id="units" value="<?php echo $units; ?>" /> <?php } ?> </p> </form> <p> </p> </div> </body> </html> I get the "Parse error: syntax error, unexpected T_ENDIF in /hsphere/local/home/x/x/links/wp-content/themes/x/single.php on line 58" error. I have highlighted line 58 below. What is wrong? Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php the_title(); ?> | X</title> <meta name="author" content="X" /> <meta name="description" content="X" /> <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo('charset'); ?>" /> <meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats please --> <style type="text/css" media="screen"> @import url( <?php bloginfo('stylesheet_url'); ?> ); </style> <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="" /> <link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" /> <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" /> </head> <div id="wrap"> <ul id="navbar"> <li><a href="http://x" alt="Index">Index</a></li> <li><a href="http://x/articles/" alt="Articles">Articles</a></li> <li><a href="http://x/links/" alt="Links">Links</a></li> <li><a href="http://x/contact/" alt="Contact">Contact</a></li> <li><a href="http://x/colophon/" alt="Colophon">Colophon</a></li> </ul> <img src="http://x/images/links.jpg" class="shadow" alt="Links of Plenty" width="640" height="320" /> <h1>Title</h1> <h4>Tagline</h4> <br> <div id="main"> <div id="content"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <?php if( in_category('ll') ) : ?> <h2 class="ll"><a href="<?php the_linked_list_link('url') ?>" rel="bookmark" title="Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <?php else : ?> <h2 class="title"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <?php endif; ?> <div class="meta"> <p>Posted on <?php the_time('M') ?> <?php the_time('d') ?> <?php the_time('Y') ?> | <a href="http://www.instapaper.com/hello2?url=<?= rawurlencode(get_permalink()) ?>&title=<?= rawurlencode(get_the_title()) ?>">Add to Instapaper</a> | <a href="http://twitter.com/share?url=<?php the_permalink() ?>">Share on Twitter</a></p> </div> <br> <div class="entry"> <?php the_content(__('Continue Reading &#187;')); ?> <?php wp_link_pages(); ?> <a href="<?php the_permalink() ?>" rel="bookmark">⌘</a> </div> <br><p align="center"><a href="http://x/links/archives/">Browse by subject, year or month</a></p> </div> LINE 58 <?php endif; ?> </div> </div> <p id="footer"><a href="http://feeds.feedburner.com/x">Articles feed</a>. <a href="http://feeds.feedburner.com/x">Links feed</a>. <a href="http://feeds.feedburner.com/x"><a href="http://x/colophon/index.html#license">License</a>. Powered by <a href="http://www.wordpress.org">Wordpress</a> and <a href="http://x/">Coffee</a>. Built with <a href="http://macrabbit.com/espresso">Espresso</a>. <a href="http://x/links/wp-login.php">Admin</a>.</p> </div> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'x']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </body> </html> Hi there! I need to echo some text from a database table, this text should be linked to a url stored in the same database. I am trying to do this with preg_replace but I am terrible at it! I keep getting this error: Warning: Wrong parameter count for preg_replace() while($row = mysql_fetch_array( $result )) { $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; echo preg_replace ($reg_exUrl, $row['title'); Any suggestion? Thanks Hello ppl, I have this website link http://www.somesite.com/anotherpage/yetotherpage.html what i want to make is using preg_replace that the final result will be www.somesite.com After days of searching I found this thread http://www.phpfreaks.com/forums/index.php?topic=236954.0 that helped me do what I was trying to do. I've gotten the code to create and rename my html document but I can't figure out how to use the preg_replace part. This is my template with the 3 variables I want to replace with values from a form. Code: [Select] <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php include_once('content.php') ?> </body> <SCRIPT language="JavaScript" SRC="javascript.js"></SCRIPT> <script type="text/javascript"> function nametitle(){ parent.iframe1.document.getElementById("div1").innerHTML = "VARIABLE1 <br>VARIABLE2"; parent.iframe1.document.getElementById("quotes").innerHTML = "VARIABLE3"; } </script> </html> I've spent hours reading and trying to understand how to make it work but it's a little over my head. Could someone help me with this? Thanks, I currently have some custom tags, similar to BBCode, to be used for comments on my site. I'm trying to create a [nobr] tag (note: I know the no break tag will work in many major browsers, but it's deprecated, so I'm trying to be compliant). The idea is that if I encounter the [nobr] tag, I need to remove all line breaks. Here's the best I can do, but it's not working as I had hoped. Here's what I currently use to replace line breaks with a break tag. Code: [Select] $str=str_replace("\r\n","<br>",$str); Here's my attempt at introducing this new tag. Code: [Select] function BbToHtml($str) { $before=preg_replace("/(.+)\[nobr\](.+)\[\/nobr\](.+)/Usi","\\1",$str); $during=preg_replace("/(.+)\[nobr\](.+)\[\/nobr\](.+)/Usi","\\2",$str); $after=preg_replace("/(.+)\[nobr\](.+)\[\/nobr\](.+)/Usi","\\3",$str); $during=str_replace("\r\n","",$during); if($during != "") { // If the [nobr] tag was found, go with the new string. $str = $before.$during.$after; } else { // If the [nobr] tag was not found, go ahead like normal. $str=str_replace("\r\n","<br>",$str); } return $str; I can't get that working. Any ideas on how to fix that, or a completely alternate method of doing it? Thank you! I'm trying to search a string for all occurences of a pattern, then append text after that pattern. The example is:
SUM("foo") as "bar"
and have it display as:
SUM("foo") over() as "bar"
The "SUM" could be any SQL aggregate and be case insensitive. So For bonus points, let's say the valid aggregates are array('SUM', 'MAX', 'MIN', 'AVG'). My plan right now is to figure it out for SUM, then loop it replacing the aggregate.
This is what I have so far... and it is not working.
$l= 'SUM("foo") as "bar"';
$l=preg_replace('/([^"]+")/','\0 over()',$l);
Thanks,
Ryan
I am trying to pull out the image HTML tag but its not working as expected. Here is what I am doing $removeimagetag='/<a href/'; $replacwith = "illegal"; $_POST['descr']=preg_replace($removeimagetag,$replacwith,$_POST['descr']); in the 'descr' there is a <a href="http://s635.photobucket.com...... When it post it does not strip out the <a href So the image is displayed. I tried a modified version to test to see if it work that looked like this. $removeimagetag='/goofy/'; $replacwith = "illegal"; $_POST['descr']=preg_replace($removeimagetag,$replacwith,$_POST['descr']); When the word goofy appears in the text then its replaced with the word illegal, Also I would like to make it so that it replaces the entire line from the <a href....... to the </a> with a phrase that says "this feature is not allowed" rather than just the part in the front...the <a href. Any help you can be will be greatly appreciated. |