RE: [PHP] Problems w/ goto
Ethan, I tried to test your code, but I get this error next to the labels and goto statements: Language feature not compatible with PHP version indicated in project settings I have PHP 5.3.0. Geoffrey _ From: Ethan Rosenberg [mailto:eth...@earthlink.net] Sent: 17 December 2010 06:39 PM To: php-db-lists.php.net; php-general@lists.php.net Subject: [PHP] Problems w/ goto Dear List - I am sending this again since it does not seem to have posted. Ethan +++ Dear List - Thank you with your excellent help in the past. Here is another puzzler I am trying to write a program that can have two(2) independent forms in one PHP file. When I run the code below [from PHP - A Beginner's Guide], to which I have added a second form, it freezes. Without the goto statements, it runs. When it does run, it displays both forms on one Web screen. What I desire is for the first form to be displayed, the data entered and then the second form displayed. In an actual, not test program like this one, the data in the second form would be dependent on the first form. What did I do wrong? Thanks in advance. Here is the code: http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en"> Project 4-4: Age Calculator Project 4-4: Age Calculator "; echo " Enter your date of birth, in mm/dd/ format: "; echo " "; echo " "; echo " "; echo " "; goto begin; // if form submitted // process form input } else { starter: if (isset($_POST['cat'])) goto purr; // split date value into components $dateArr = explode('/', $_POST['dob']); // calculate timestamp corresponding to date value $dateTs = strtotime($_POST['dob']); // calculate timestamp corresponding to 'today' $now = strtotime('today'); // check that the value entered is in the correct format if (sizeof($dateArr) != 3) { die('ERROR: Please enter a valid date of birth'); } // check that the value entered is a valid date if (!checkdate($dateArr[0], $dateArr[1], $dateArr[2])) { die('ERROR: Please enter a valid date of birth'); } // check that the date entered is earlier than 'today' if ($dateTs >= $now) { die('ERROR: Please enter a date of birth earlier than today'); } // calculate difference between date of birth and today in days // convert to years // convert remaining days to months // print output $ageDays = floor(($now - $dateTs) / 86400); $ageYears = floor($ageDays / 365); $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30); echo "You are approximately $ageYears years and $ageMonths months old."; goto meow; } meow: if (!isset($_POST['dob'])) goto begin; if (!isset($_POST['cat'])) { echo " "; echo " Enter your kitten's name: "; echo " "; echo " "; echo " "; echo ""; } else { purr: $name_cat = $_POST['cat']; echo "Your Kitten is $name_cat"; $ender = 1; } if ($ender == 0) goto begin; first_step: ?> Ethan MySQL 5.1 PHP 5 Linux [Debian (sid)] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ No virus found in this message. Checked by AVG - www.avg.com Version: 10.0.1170 / Virus Database: 1435/3323 - Release Date: 12/18/10
[PHP] Hot to replace words with preg_replace without duplicates
Hi there, I want to create a function which will replace certain words out of a text with internal links. That works so far, but if I have two matches, I end up with invalid html code. Example: Welpen /hunde Chihuahua Welpen/hunde,chihuahua function seo_internal_links($str, $links, $limit) { foreach($links AS $link){ $pattern[$k] = "~\b($link[phrase])\b~i"; $replace[$k] = '\\1'; $k++; } return preg_replace($pattern,$replace,$str, $limit); } seo_internal_links($ad[text], $seo_internal_links, $limit = 1); This will result in: Chihuahua Welpen Has somebody an idea on how to avoid this? I would also like to limit the amount of hits, but the limit in preg_replace accounts only for unique words, not the whole array. Thank you for any hint, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML id attribute and arrays
What are you trying to accomplish? What do you think it wrong with the code below? On 12/17/2010 8:19 AM, Martin C wrote: Hi, PHP converts x[a]=b parameter of the HTTP request as an array named x with its item named a set to value b. So, it seems possible to have the following (X)HTML code: Unfortunatelly, HTML specification does not allow neither "[" nor "]" inside the id attribute. Specifically: * Must begin with a letter A-Z or a-z * Can be followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), underscores ("_"), colons (":"), and periods (".") * Values are case-sensitive How should I follow the HTML specification while having the passed parameters automatically converted to arrays in PHP? Thank you for any tips, Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems w/ goto
On Sat, Dec 18, 2010 at 12:45 PM, Geoffrey Bernardo Van Wyk wrote: > Ethan, > > I tried to test your code, but I get this error next to the labels and goto > statements: As a 'professional' programmer, working for an entity, we deal with these problems as we go. As novices, we deal with it on a daily basis. As computer scientists, we think of it as a problem already solved, but in need of translation. Understand, buddy pal. > > Language feature not compatible with PHP version indicated in project > settings > > I have PHP 5.3.0. > > Geoffrey > > _ > > From: Ethan Rosenberg [mailto:eth...@earthlink.net] > Sent: 17 December 2010 06:39 PM > To: php-db-lists.php.net; php-general@lists.php.net > Subject: [PHP] Problems w/ goto > > > > Dear List - > > I am sending this again since it does not seem to have posted. > > Ethan > +++ > Dear List - > > Thank you with your excellent help in the past. Here is another puzzler > > > I am trying to write a program that can have two(2) independent forms > in one PHP file. When I run the code below [from PHP - A Beginner's > Guide], to which I have added a second form, it freezes. Without the > goto statements, it runs. When it does run, it displays both forms > on one Web screen. What I desire is for the first form to be > displayed, the data entered and then the second form displayed. In > an actual, not test program like this one, the data in the second > form would be dependent on the first form. > > What did I do wrong? > > Thanks in advance. > > Here is the code: > > > "DTD/xhtml1-transitional.dtd"> > http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en"> > > Project 4-4: Age Calculator > > > Project 4-4: Age Calculator > // if form not yet submitted > // display form > > $ender = 0; > begin: > > if($ender == 1) > exit(); > if (!isset($_POST['dob'])) > { > start1: > > echo " "; > echo " Enter your date of birth, in mm/dd/ format: "; > echo " "; > echo " "; > echo " "; > echo " "; > > goto begin; > // if form submitted > // process form input > } > else > { > starter: > if (isset($_POST['cat'])) > goto purr; > // split date value into components > $dateArr = explode('/', $_POST['dob']); > > // calculate timestamp corresponding to date value > $dateTs = strtotime($_POST['dob']); > > // calculate timestamp corresponding to 'today' > $now = strtotime('today'); > > // check that the value entered is in the correct format > if (sizeof($dateArr) != 3) { > die('ERROR: Please enter a valid date of birth'); > } > > // check that the value entered is a valid date > if (!checkdate($dateArr[0], $dateArr[1], $dateArr[2])) { > die('ERROR: Please enter a valid date of birth'); > } > > // check that the date entered is earlier than 'today' > if ($dateTs >= $now) { > die('ERROR: Please enter a date of birth earlier than today'); > } > > // calculate difference between date of birth and today in days > // convert to years > // convert remaining days to months > // print output > $ageDays = floor(($now - $dateTs) / 86400); > $ageYears = floor($ageDays / 365); > $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30); > echo "You are approximately $ageYears years and $ageMonths months > old."; > goto meow; > } > > meow: > if (!isset($_POST['dob'])) > goto begin; > if (!isset($_POST['cat'])) > { > > > echo " "; > echo " Enter your kitten's name: "; > echo " "; > echo " "; > echo " Kitten\" />"; > echo " "; > > } > else > { > purr: > $name_cat = $_POST['cat']; > > echo "Your Kitten is $name_cat"; > $ender = 1; > } > if ($ender == 0) > goto begin; > first_step: > ?> > > > > > > > Ethan > > MySQL 5.1 PHP 5 Linux [Debian (sid)] > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > _ > > No virus found in this message. > Checked by AVG - www.avg.com > Version: 10.0.1170 / Virus Database: 1435/3323 - Release Date: 12/18/10 > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems w/ goto
You approved all of us, no matter the peer review, when you signed up or the list. The accumulation of knowledge, is insurmountable when delivered as a whole, but devourable if you need satiation of appetite. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems w/ goto
or maybe it's saturday morning and i'm drunk? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems w/ goto
check out my new sig. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array question
On 12/17/2010 12:52 PM, Sorin Buturugeanu wrote: Hello all! I have a question regarding arrays and the way I can use a value. Let's say I have this string: $s = 'banana,apple,mellon,grape,nut,orange' I want to explode it, and get the third value. For this I would normally do: $a = explode(',', $s); echo $s[2]; That's all fine, but is there a way to get the value directly, without having to write another line in my script. I mean something like this: echo explode(',', $s)[2]; or echo {explode(',', $s)}[2]; I couldn't find out this answer anywhere, that's why I posted here. Cheers and thanks! Sure it CAN be done. Nobody laugh too loud here... But... Outputs: grape The {3} part is equivalent to the array position. Change that number, and you change which word will get displayed. Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHPmailer.. best way to send to many recipients?
Hi everyone, I just started using PHPmailer for one project that requires SMTP authentication (if I said that right).. and all is well.. but I want to ask now before it might get outta hand later: How many comma-delim'ed addresses can I stuff in $BCC_recipients before I have problems (need to restructure the design)? -- require("php_inc/class.phpmailer.php"); $mail = new PHPMailer(); $BCC_recipients = "x...@host.com,y...@server.com"; // <---just an example $arrBCC_recipients = explode(",", $BCC_recipients); foreach ($arrBCC_recipients as $email2stuffInBCC) { $mail->AddBcc($email2stuffInBCC); } if(!$mail->Send()) { // problem -- For now there will be less than 100 Bcc recipients.. but later, more. I don't know if/when it will ever grow past 1,000. Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] goto - My comments
Dear List - Thanks to all for your EXCELLENT comments. I definitly agree that goto is a command to be avoided at all costs. In this case, I could not figure out how to acheive the desired result without the goto. So being a newbie, I humbly request that you show [and at the same time teach] me how to rewrite the code to eleiminate the goto. Additionally, would you please do the same for the code I list below. This code runs perfectly. == This is the form: Data Search Data Search Site: Record Number: First Name: Last Name: Phone: Height: Male Female *** This is the program - Search of Data "); //printf($sql1); $result = mysqli_query($cxn, $sql1); if(($num = mysqli_num_rows($result)) == 0) die ("No Records Retrieved"); ?> Search Results cellspacing="55" rules="all" frame="box"> Site Medical Record First Name Last Name Phone Height Sex History // printf("To exit, click the EXIT button below./>"); // printf("%s\t%s\t%s\t%s\t%s","Site","Record", "Weight", "Height", "BMI"); while($row = mysqli_fetch_array($result)) { echo "\n"; echo " $row[0] \n"; echo " $row[1] \n"; echo " $row[3] \n"; echo " $row[4] \n"; echo " $row[2] \n"; echo " $row[5] \n"; echo " $row[6] \n"; echo " $row[7] \n"; echo "\n"; /* $site2 = $row[0]; $record2 = $row[1]; $bmi2 = $row[2]; $wgt2 = $row[3]; $hgt2 = $row[4]; printf("%s\t%d\t%d\t%d\t%3.1f", $site2, $record2, $wgt2, $hgt2, $bmi2);*/ } /*printf("%s\t%s\t%s\t%s\t%s","Site","Record", "BMI", "Weight", "Height"); printf(""); while( $row = mysqli_fetch_array($result)) { $site2 = $row[0]; $record2 = $row[1]; $bmi2 = $row[2]; $wgt2 = $row[3]; $hgt2 = $row[4]; printf("%s\t%d\t%3.1f\t%d\t%d", $site2, $record2, $bmi2, $wgt2, $hgt2); }*/ mysqli_free_result($result); mysqli_close($cxn); ?> == THANK YOU EVER SO MUCH FOR YOUR HELP. Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] goto - My comments
On 10-12-19 12:17 AM, Ethan Rosenberg wrote: Dear List - Thanks to all for your EXCELLENT comments. I definitly agree that goto is a command to be avoided at all costs. Closed-minded drivel (or you're buttering up the popular opinion crowd). A better approach is that goto should be used with caution. As for doing your homework for you... ummm no thanks. You should take the time to do the exercise so you gain the benefit of experience. Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] goto - My comments
On Sat, Dec 18, 2010 at 11:44 PM, Robert Cummings wrote: > On 10-12-19 12:17 AM, Ethan Rosenberg wrote: >> >> Dear List - >> >> Thanks to all for your EXCELLENT comments. I definitly agree that >> goto is a command to be avoided at all costs. > > Closed-minded drivel (or you're buttering up the popular opinion crowd). A > better approach is that goto should be used with caution. > > As for doing your homework for you... ummm no thanks. You should take the > time to do the exercise so you gain the benefit of experience. I would have thought school would have been out on account of Christmas and all. In any event, here's my rewrite: switch (true) { case isset($_POST['Site']) && trim($_POST['Site']) != '': $sql1 = $sql1 . "site = '$ste'"; break; case isset($_POST['MedRec'])&& trim($_POST['MedRe']) != '': $sql1 = $sql1 . "MedRec = '$req'"; break; // ... default: if(isset($_Request['Sex'])&& trim($_POST['Sex']) != '' ) { if ($_REQUEST["Sex"] == "0") $sex = 'Male'; else $sex = 'Female'; $sql1 = $sql1 . " = '$sex'"; $sexdone = 1; } if(isset($_POST['Hx'])&& trim($_POST['Hx']) != '') { $sql1 = $sql1 . "Hx = '$hx'"; $done = 1; } } You could also do an if / else if / else if / ... / else. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php