Re: [PHP] Converting date string to unix timestamp
On Fri, May 11, 2012 at 8:46 PM, Karl DeSaulniers k...@designdrumm.com wrote: On another note, just curious why I keep getting your responses, but don't get the emails that I post. Anyone else having trouble with the list like that? That is how the mailing list works. You don't see the messages you send. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting date string to unix timestamp
On another note, just curious why I keep getting your responses, but don't get the emails that I post. Anyone else having trouble with the list like that? That is how the mailing list works. You don't see the messages you send. If you want to see your post, you can check (drill down) here: http://marc.info/?l=php-general -Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting date string to unix timestamp
On 05/11/2012 04:11 PM, Karl DeSaulniers wrote: Hello everyone, Got a quick one (I hope), and probably an easy one. For some reason it is eluding me at the moment. Hoping someone can help. I am building an ics file with PHP and the form that is submitting to create this ics file has a jQuery date picker on it. The date furnished comes to me like this Saturday, January 1, 2012, and a time furnished like 4:20 pm with no seconds. Now for the ics file, I need the date/time combo to be.. Ymd\THis\Z or in the case of the above date and time, 20120101T042000Z Here is the block of code that I am using for this. Why do you have so much code to do such a simple thing? This works for me. ?php $date = Saturday, January 1, 2012; $time = 4:20 pm; echo date('Ymd\THis\Z', strtotime($date.' '.$time)); // Outputs 20120107T162000Z ? Check it out in action: http://www.cmsws.com/examples/php/jquery_time_stamp.php http://www.cmsws.com/examples/php/jquery_time_stamp.phps Jim CODE [ ... } else { $dt_start = $_POST[field20] ? $_POST[field20] : $_POST[field21]; //Saturday, January 1, 2012 $dt_end = $_POST[field22]; //Saturday, January 1, 2012 $t_start = $_POST[field24]; //4:20 pm $t_end = $_POST[field25]; //5:55 pm //date_default_timezone_set('UTC'); try { $start_DT = new DateTime($dt_start . . $t_start); $st_date_fmt = new DateTime($start_DT-format(l, F d, Y\TH:ia T)); //$startdate_stamp = strtotime($st_date_fmt); $startdate = $st_date_fmt-format('U'); //$startdate = date('Ymd\THis\Z', $startdate_stamp); } catch (Exception $e) { trigger_error(startdate error: . $e-getMessage(), E_USER_ERROR); exit(1); } try { if(empty($dt_end)) { $enddate = $startdate + (60 * 60); //If no end date provided, enddate is 1 hour after startdate. } else { $end_DT = new DateTime($dt_end . . $t_end); $end_date_fmt = new DateTime($end_DT-format(l, F d, Y\TH:ia T)); //$enddate_stamp = strtotime($end_date_fmt); $enddate = $end_date_fmt-format('U'); //$enddate = date('Ymd\THis\Z', $enddate_stamp); } } catch (Exception $e) { trigger_error(enddate error: . $e-getMessage(), E_USER_ERROR); exit(1); } $stampnow = date('Ymd\THis\Z', time()); //$datestampnow = strtotime($stampnow); } ... ] I have a feeling I am mixing something up on my own, but I have been staring at this code to long to see it. Can anyone help me please? Like I said, this is probably an easy one. TIA!! Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting date string to unix timestamp
Thanks Jim, To tell you the truth, this was handed off to me. Thank you for the response. I knew this was just bloated code. Thanks for verifying that for me. :) Just one question, why does it echo the 7th and not the 1st? Should be 20120101T162000Z not 20120107T162000Z Best, Karl On May 11, 2012, at 7:42 PM, Jim Lucas wrote: On 05/11/2012 04:11 PM, Karl DeSaulniers wrote: Hello everyone, Got a quick one (I hope), and probably an easy one. For some reason it is eluding me at the moment. Hoping someone can help. I am building an ics file with PHP and the form that is submitting to create this ics file has a jQuery date picker on it. The date furnished comes to me like this Saturday, January 1, 2012, and a time furnished like 4:20 pm with no seconds. Now for the ics file, I need the date/time combo to be.. Ymd\THis\Z or in the case of the above date and time, 20120101T042000Z Here is the block of code that I am using for this. Why do you have so much code to do such a simple thing? This works for me. ?php $date = Saturday, January 1, 2012; $time = 4:20 pm; echo date('Ymd\THis\Z', strtotime($date.' '.$time)); // Outputs 20120107T162000Z ? Check it out in action: http://www.cmsws.com/examples/php/jquery_time_stamp.php http://www.cmsws.com/examples/php/jquery_time_stamp.phps Jim CODE [ ... } else { $dt_start = $_POST[field20] ? $_POST[field20] : $_POST[field21]; //Saturday, January 1, 2012 $dt_end = $_POST[field22]; //Saturday, January 1, 2012 $t_start = $_POST[field24]; //4:20 pm $t_end = $_POST[field25]; //5:55 pm //date_default_timezone_set('UTC'); try { $start_DT = new DateTime($dt_start . . $t_start); $st_date_fmt = new DateTime($start_DT-format(l, F d, Y\TH:ia T)); //$startdate_stamp = strtotime($st_date_fmt); $startdate = $st_date_fmt-format('U'); //$startdate = date('Ymd\THis\Z', $startdate_stamp); } catch (Exception $e) { trigger_error(startdate error: . $e-getMessage(), E_USER_ERROR); exit(1); } try { if(empty($dt_end)) { $enddate = $startdate + (60 * 60); //If no end date provided, enddate is 1 hour after startdate. } else { $end_DT = new DateTime($dt_end . . $t_end); $end_date_fmt = new DateTime($end_DT-format(l, F d, Y\TH:ia T)); //$enddate_stamp = strtotime($end_date_fmt); $enddate = $end_date_fmt-format('U'); //$enddate = date('Ymd\THis\Z', $enddate_stamp); } } catch (Exception $e) { trigger_error(enddate error: . $e-getMessage(), E_USER_ERROR); exit(1); } $stampnow = date('Ymd\THis\Z', time()); //$datestampnow = strtotime($stampnow); } ... ] I have a feeling I am mixing something up on my own, but I have been staring at this code to long to see it. Can anyone help me please? Like I said, this is probably an easy one. TIA!! Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting date string to unix timestamp
Never mind, it's because January 1st is not a Saturday. The 7th is. Interesting... so it corrects the date per the text representation of the day?? Thanks again. Best, Karl On May 11, 2012, at 7:42 PM, Jim Lucas wrote: On 05/11/2012 04:11 PM, Karl DeSaulniers wrote: Hello everyone, Got a quick one (I hope), and probably an easy one. For some reason it is eluding me at the moment. Hoping someone can help. I am building an ics file with PHP and the form that is submitting to create this ics file has a jQuery date picker on it. The date furnished comes to me like this Saturday, January 1, 2012, and a time furnished like 4:20 pm with no seconds. Now for the ics file, I need the date/time combo to be.. Ymd\THis\Z or in the case of the above date and time, 20120101T042000Z Here is the block of code that I am using for this. Why do you have so much code to do such a simple thing? This works for me. ?php $date = Saturday, January 1, 2012; $time = 4:20 pm; echo date('Ymd\THis\Z', strtotime($date.' '.$time)); // Outputs 20120107T162000Z ? Check it out in action: http://www.cmsws.com/examples/php/jquery_time_stamp.php http://www.cmsws.com/examples/php/jquery_time_stamp.phps Jim CODE [ ... } else { $dt_start = $_POST[field20] ? $_POST[field20] : $_POST[field21]; //Saturday, January 1, 2012 $dt_end = $_POST[field22]; //Saturday, January 1, 2012 $t_start = $_POST[field24]; //4:20 pm $t_end = $_POST[field25]; //5:55 pm //date_default_timezone_set('UTC'); try { $start_DT = new DateTime($dt_start . . $t_start); $st_date_fmt = new DateTime($start_DT-format(l, F d, Y\TH:ia T)); //$startdate_stamp = strtotime($st_date_fmt); $startdate = $st_date_fmt-format('U'); //$startdate = date('Ymd\THis\Z', $startdate_stamp); } catch (Exception $e) { trigger_error(startdate error: . $e-getMessage(), E_USER_ERROR); exit(1); } try { if(empty($dt_end)) { $enddate = $startdate + (60 * 60); //If no end date provided, enddate is 1 hour after startdate. } else { $end_DT = new DateTime($dt_end . . $t_end); $end_date_fmt = new DateTime($end_DT-format(l, F d, Y\TH:ia T)); //$enddate_stamp = strtotime($end_date_fmt); $enddate = $end_date_fmt-format('U'); //$enddate = date('Ymd\THis\Z', $enddate_stamp); } } catch (Exception $e) { trigger_error(enddate error: . $e-getMessage(), E_USER_ERROR); exit(1); } $stampnow = date('Ymd\THis\Z', time()); //$datestampnow = strtotime($stampnow); } ... ] I have a feeling I am mixing something up on my own, but I have been staring at this code to long to see it. Can anyone help me please? Like I said, this is probably an easy one. TIA!! Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting date string to unix timestamp
On 05/11/2012 05:55 PM, Karl DeSaulniers wrote: Thanks Jim, To tell you the truth, this was handed off to me. Thank you for the response. I knew this was just bloated code. Thanks for verifying that for me. :) Just one question, why does it echo the 7th and not the 1st? I see that... Figuring their is a logical reason... Ah! The first Saturday in the month of January this year WAS the 7th. The 1st was on a Sunday. I would say that your date picker has issues. Should be 20120101T162000Z not 20120107T162000Z Best, Karl On May 11, 2012, at 7:42 PM, Jim Lucas wrote: On 05/11/2012 04:11 PM, Karl DeSaulniers wrote: Hello everyone, Got a quick one (I hope), and probably an easy one. For some reason it is eluding me at the moment. Hoping someone can help. I am building an ics file with PHP and the form that is submitting to create this ics file has a jQuery date picker on it. The date furnished comes to me like this Saturday, January 1, 2012, and a time furnished like 4:20 pm with no seconds. Now for the ics file, I need the date/time combo to be.. Ymd\THis\Z or in the case of the above date and time, 20120101T042000Z Here is the block of code that I am using for this. Why do you have so much code to do such a simple thing? This works for me. ?php $date = Saturday, January 1, 2012; $time = 4:20 pm; echo date('Ymd\THis\Z', strtotime($date.' '.$time)); // Outputs 20120107T162000Z ? Check it out in action: http://www.cmsws.com/examples/php/jquery_time_stamp.php http://www.cmsws.com/examples/php/jquery_time_stamp.phps Jim CODE [ ... } else { $dt_start = $_POST[field20] ? $_POST[field20] : $_POST[field21]; //Saturday, January 1, 2012 $dt_end = $_POST[field22]; //Saturday, January 1, 2012 $t_start = $_POST[field24]; //4:20 pm $t_end = $_POST[field25]; //5:55 pm //date_default_timezone_set('UTC'); try { $start_DT = new DateTime($dt_start . . $t_start); $st_date_fmt = new DateTime($start_DT-format(l, F d, Y\TH:ia T)); //$startdate_stamp = strtotime($st_date_fmt); $startdate = $st_date_fmt-format('U'); //$startdate = date('Ymd\THis\Z', $startdate_stamp); } catch (Exception $e) { trigger_error(startdate error: . $e-getMessage(), E_USER_ERROR); exit(1); } try { if(empty($dt_end)) { $enddate = $startdate + (60 * 60); //If no end date provided, enddate is 1 hour after startdate. } else { $end_DT = new DateTime($dt_end . . $t_end); $end_date_fmt = new DateTime($end_DT-format(l, F d, Y\TH:ia T)); //$enddate_stamp = strtotime($end_date_fmt); $enddate = $end_date_fmt-format('U'); //$enddate = date('Ymd\THis\Z', $enddate_stamp); } } catch (Exception $e) { trigger_error(enddate error: . $e-getMessage(), E_USER_ERROR); exit(1); } $stampnow = date('Ymd\THis\Z', time()); //$datestampnow = strtotime($stampnow); } ... ] I have a feeling I am mixing something up on my own, but I have been staring at this code to long to see it. Can anyone help me please? Like I said, this is probably an easy one. TIA!! Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting date string to unix timestamp
Oh,.. no it works just fine. I wrote Saturday myself not looking to see if it was actually the 1st. My fault for a non-existent date. Thanks for your help though, looks like that did the trick. On another note, just curious why I keep getting your responses, but don't get the emails that I post. Anyone else having trouble with the list like that? Best, Karl On May 11, 2012, at 8:06 PM, Jim Lucas wrote: On 05/11/2012 05:55 PM, Karl DeSaulniers wrote: Thanks Jim, To tell you the truth, this was handed off to me. Thank you for the response. I knew this was just bloated code. Thanks for verifying that for me. :) Just one question, why does it echo the 7th and not the 1st? I see that... Figuring their is a logical reason... Ah! The first Saturday in the month of January this year WAS the 7th. The 1st was on a Sunday. I would say that your date picker has issues. Should be 20120101T162000Z not 20120107T162000Z Best, Karl On May 11, 2012, at 7:42 PM, Jim Lucas wrote: On 05/11/2012 04:11 PM, Karl DeSaulniers wrote: Hello everyone, Got a quick one (I hope), and probably an easy one. For some reason it is eluding me at the moment. Hoping someone can help. I am building an ics file with PHP and the form that is submitting to create this ics file has a jQuery date picker on it. The date furnished comes to me like this Saturday, January 1, 2012, and a time furnished like 4:20 pm with no seconds. Now for the ics file, I need the date/time combo to be.. Ymd\THis\Z or in the case of the above date and time, 20120101T042000Z Here is the block of code that I am using for this. Why do you have so much code to do such a simple thing? This works for me. ?php $date = Saturday, January 1, 2012; $time = 4:20 pm; echo date('Ymd\THis\Z', strtotime($date.' '.$time)); // Outputs 20120107T162000Z ? Check it out in action: http://www.cmsws.com/examples/php/jquery_time_stamp.php http://www.cmsws.com/examples/php/jquery_time_stamp.phps Jim CODE [ ... } else { $dt_start = $_POST[field20] ? $_POST[field20] : $_POST[field21]; //Saturday, January 1, 2012 $dt_end = $_POST[field22]; //Saturday, January 1, 2012 $t_start = $_POST[field24]; //4:20 pm $t_end = $_POST[field25]; //5:55 pm //date_default_timezone_set('UTC'); try { $start_DT = new DateTime($dt_start . . $t_start); $st_date_fmt = new DateTime($start_DT-format(l, F d, Y\TH:ia T)); //$startdate_stamp = strtotime($st_date_fmt); $startdate = $st_date_fmt-format('U'); //$startdate = date('Ymd\THis\Z', $startdate_stamp); } catch (Exception $e) { trigger_error(startdate error: . $e-getMessage(), E_USER_ERROR); exit(1); } try { if(empty($dt_end)) { $enddate = $startdate + (60 * 60); //If no end date provided, enddate is 1 hour after startdate. } else { $end_DT = new DateTime($dt_end . . $t_end); $end_date_fmt = new DateTime($end_DT-format(l, F d, Y\TH:ia T)); //$enddate_stamp = strtotime($end_date_fmt); $enddate = $end_date_fmt-format('U'); //$enddate = date('Ymd\THis\Z', $enddate_stamp); } } catch (Exception $e) { trigger_error(enddate error: . $e-getMessage(), E_USER_ERROR); exit(1); } $stampnow = date('Ymd\THis\Z', time()); //$datestampnow = strtotime($stampnow); } ... ] I have a feeling I am mixing something up on my own, but I have been staring at this code to long to see it. Can anyone help me please? Like I said, this is probably an easy one. TIA!! Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ Karl DeSaulniers Design Drumm http://designdrumm.com -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Converting a string
[snip] If you have similar element names in $_POST, comething like: $human_friendly = array(psFirstName = First Name); foreach ($_POST as $ key = value) { echo Cannot leave {$human_friendly[$key]} blank; } [/snip] But I don't want to create another array, and should'nt have to
RE: [PHP] Converting a string
Try using preg_match_all with this pattern: /([A-Z].*[^A-Z])/U While this pattern does not get you exactly what you want, I think it serves as a starting point. I am not too good with regular expressions so I'll let the more accomplished regex people on the list jump in at this point. Shaunak Kashyap Senior Web Developer WPT Enterprises, Inc. 5700 Wilshire Blvd., Suite 350 Los Angeles, CA 90036 Direct: 323.330.9870 Main: 323.330.9900 www.worldpokertour.com Confidentiality Notice: This e-mail transmission (and/or the attachments accompanying) it may contain confidential information belonging to the sender which is protected. The information is intended only for the use of the intended recipient. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this information is prohibited. If you have received this transmission in error, please notify the sender by reply e-mail and destroy all copies of this transmission. -Original Message- From: Jay Blanchard [mailto:[EMAIL PROTECTED] Sent: Friday, March 17, 2006 10:24 AM To: Dave Goodchild Cc: php-general@lists.php.net Subject: RE: [PHP] Converting a string [snip] If you have similar element names in $_POST, comething like: $human_friendly = array(psFirstName = First Name); foreach ($_POST as $ key = value) { echo Cannot leave {$human_friendly[$key]} blank; } [/snip] But I don't want to create another array, and should'nt have to -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Converting a string
I think I got the correct regex pattern: /[A-Z].*.[^A-Z]/U Again, I am not too good with regex so I can't explain why that pattern works and also if it will work in all cases. HTH, Shaunak Kashyap Senior Web Developer WPT Enterprises, Inc. 5700 Wilshire Blvd., Suite 350 Los Angeles, CA 90036 Direct: 323.330.9870 Main: 323.330.9900 www.worldpokertour.com Confidentiality Notice: This e-mail transmission (and/or the attachments accompanying) it may contain confidential information belonging to the sender which is protected. The information is intended only for the use of the intended recipient. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this information is prohibited. If you have received this transmission in error, please notify the sender by reply e-mail and destroy all copies of this transmission. -Original Message- From: Shaunak Kashyap [mailto:[EMAIL PROTECTED] Sent: Friday, March 17, 2006 10:49 AM To: Jay Blanchard; Dave Goodchild Cc: php-general@lists.php.net Subject: RE: [PHP] Converting a string Try using preg_match_all with this pattern: /([A-Z].*[^A-Z])/U While this pattern does not get you exactly what you want, I think it serves as a starting point. I am not too good with regular expressions so I'll let the more accomplished regex people on the list jump in at this point. Shaunak Kashyap Senior Web Developer WPT Enterprises, Inc. 5700 Wilshire Blvd., Suite 350 Los Angeles, CA 90036 Direct: 323.330.9870 Main: 323.330.9900 www.worldpokertour.com Confidentiality Notice: This e-mail transmission (and/or the attachments accompanying) it may contain confidential information belonging to the sender which is protected. The information is intended only for the use of the intended recipient. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this information is prohibited. If you have received this transmission in error, please notify the sender by reply e-mail and destroy all copies of this transmission. -Original Message- From: Jay Blanchard [mailto:[EMAIL PROTECTED] Sent: Friday, March 17, 2006 10:24 AM To: Dave Goodchild Cc: php-general@lists.php.net Subject: RE: [PHP] Converting a string [snip] If you have similar element names in $_POST, comething like: $human_friendly = array(psFirstName = First Name); foreach ($_POST as $ key = value) { echo Cannot leave {$human_friendly[$key]} blank; } [/snip] But I don't want to create another array, and should'nt have to -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting a string
Jay Blanchard wrote: [snip] If you have similar element names in $_POST, comething like: $human_friendly = array(psFirstName = First Name); foreach ($_POST as $ key = value) { echo Cannot leave {$human_friendly[$key]} blank; } [/snip] But I don't want to create another array, and should'nt have to Then you should change the name of the field. Seriously, what do you expect the script to do, exactly? and once you know the answer, what would you do to achieve that? Put that (emphasis to the second question) in words and someone might be able to help you. -- Atentamente, J. Rafael Salazar Magaña Innox - Innovación Inteligente Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE http://www.innox.com.mx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Converting a string
[snip] Then you should change the name of the field. Seriously, what do you expect the script to do, exactly? and once you know the answer, what would you do to achieve that? Put that (emphasis to the second question) in words and someone might be able to help you. [/snip] I expect that I can take a string, like 'psFirstName' and change it to 'First Name'. that way I don't have to worry about what some web designer named his fields, I can turn them into human readable strings without having to manually create a new array. So far I have this $newKey = preg_split(/([A-Z])/, substr($key, 2), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); Which returns; Array ( [0] = F [1] = irst [2] = N [3] = ame ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting a string
You're best off using an array that matches human readable form to field name as someone else suggested earlier. Form names for basic fields like this should be standardized such that auto form fillers (aka Google toolbar) are able to work. They won't know that your field named hmnrdble_F-irst_N-ame equates to a first name field. Skip the dastardly regexp and keep it simple. On the posted to page populate the array with boolean values as you do you boundary checking. If you fail, then save it to session, redirect back to the form, read the array from session, and you have access to ALL fields that failed, so you can not only have a message at top, but the ability to mark each field with a style or some such to visually draw the user to what they need to fix. -Myk OLeary [EMAIL PROTECTED] BLOG: http://www.blueneedle.com/wordpress/?bnphplists On Mar 17, 2006, at 11:21 AM, Jay Blanchard wrote: [snip] Then you should change the name of the field. Seriously, what do you expect the script to do, exactly? and once you know the answer, what would you do to achieve that? Put that (emphasis to the second question) in words and someone might be able to help you. [/snip] I expect that I can take a string, like 'psFirstName' and change it to 'First Name'. that way I don't have to worry about what some web designer named his fields, I can turn them into human readable strings without having to manually create a new array. So far I have this $newKey = preg_split(/([A-Z])/, substr($key, 2), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); Which returns; Array ( [0] = F [1] = irst [2] = N [3] = ame ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Converting a string
[snip] You're best off using an array that matches human readable form to field name as someone else suggested earlier. Form names for basic fields like this should be standardized such that auto form fillers (aka Google toolbar) are able to work. They won't know that your field named hmnrdble_F-irst_N-ame equates to a first name field. Skip the dastardly regexp and keep it simple. [/snip] Scared of regex? Since this is an Intranet application we do not care about auto form fillers and actually discourage reliance on them in these cases. You're suggesting that I make the programmers do more work when there is a solution that will work regardless of what the web designers name form fields as long as the web designers stick to a naming convention policy (studly caps) for form fields. I suppose I could make them change to underscore delimited field names and it would solve my current problem. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting a string
Well, you didn't answer the second question, how would you do it? So far I see a pattern: ignore the lowercase letters at the beginnig and add a space before an uppercase (this won't apply to all field names, and I hope you're aware of that), so try something like $text = preg_replace('/^[a-z]+\s*/X', '', preg_replace('/(?=[A-Z])/X', ' ', $name) ); Now, a better way, IMHO, would be to use _ as spaces and write the name of the field as you want it to appear (e.g. First_Name), so you just need to $text = str_replace('_', ' ', $name); --pretty much simplier, isn't? And... if you want to add a prefix (such as ps) then make it configurable, so it can be changed anytime without effort. Last comment: you should think about the question you didn't answer, and that might give you the solution to your problem. Jay Blanchard wrote: [snip] Then you should change the name of the field. Seriously, what do you expect the script to do, exactly? and once you know the answer, what would you do to achieve that? Put that (emphasis to the second question) in words and someone might be able to help you. [/snip] I expect that I can take a string, like 'psFirstName' and change it to 'First Name'. that way I don't have to worry about what some web designer named his fields, I can turn them into human readable strings without having to manually create a new array. So far I have this $newKey = preg_split(/([A-Z])/, substr($key, 2), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); Which returns; Array ( [0] = F [1] = irst [2] = N [3] = ame ) -- Atentamente, J. Rafael Salazar Magaña Innox - Innovación Inteligente Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE http://www.innox.com.mx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Converting a string
[snip] Well, you didn't answer the second question, how would you do it? So far I see a pattern: ignore the lowercase letters at the beginnig and add a space before an uppercase (this won't apply to all field names, and I hope you're aware of that), so try something like $text = preg_replace('/^[a-z]+\s*/X', '', preg_replace('/(?=[A-Z])/X', ' ', $name) ); Now, a better way, IMHO, would be to use _ as spaces and write the name of the field as you want it to appear (e.g. First_Name), so you just need to $text = str_replace('_', ' ', $name); --pretty much simplier, isn't? And... if you want to add a prefix (such as ps) then make it configurable, so it can be changed anytime without effort. Last comment: you should think about the question you didn't answer, and that might give you the solution to your problem. [/snip] I was just headed in the wrong direction with preg_split(), and I had it stuck in my head. If I had delimiters, such as underscores, this question would have never come up. I am not in a position to tell the designers that we need them to change their naming conventions in forms at this unfortunately, so I need to work with what we have as efficiently as possible. Thank you for an elegant solution, but I am curiouswhy would it not work with all field names if they were named using the conventions (studly caps)? I can see a problem perhaps with a field named fooMyURL, it would come out as My U R L. Do you feel as if there are any other gotcha's? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting a string
IMHO, you do are in position to tell the designers how the fields should be named, after all they won't give any use to them, it's you (or the developer in turn) who will deal with them. Besides, using underscores (or any other space-replacement) anyone knows beforehand what the text displayed will be, and any special combination of lower/upper-case letters it's preserved. Anyway, right now it seems this is something we can't depend on, so let's refine the expression a little. Oh, and I was refering to the same problem with fields such as MyURL. I've changed a little the pattern, now it would say ignore the initial lower-case letters and spaces (if any of those) and add a space before any upper-case wich is not preceeded by an upper-case, and also those upper-case followed by a lower-case, so it now would look like $rex_initial = '/^[a-z]*\s*/X'; $rex_upper = '/(?![A-Z])(?=[A-Z])|(?=[A-Z][^A-Z])/X'; $text= preg_replace($rex_initial, '', preg_replace($rex_upper, ' ', $name) ); I think that solves the problem with the previous one. But I'd also like to point out that most of us (you included, if I understood right) seem to agree that this shouldn't be the first option, but something simplier --this is more like a patch than a feature ;) Good luck with the designers :) Jay Blanchard wrote: [···] I was just headed in the wrong direction with preg_split(), and I had it stuck in my head. If I had delimiters, such as underscores, this question would have never come up. I am not in a position to tell the designers that we need them to change their naming conventions in forms at this unfortunately, so I need to work with what we have as efficiently as possible. Thank you for an elegant solution, but I am curiouswhy would it not work with all field names if they were named using the conventions (studly caps)? I can see a problem perhaps with a field named fooMyURL, it would come out as My U R L. Do you feel as if there are any other gotcha's? -- Atentamente, J. Rafael Salazar Magaña Innox - Innovación Inteligente Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE http://www.innox.com.mx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Converting a string
[snip] IMHO, you do are in position to tell the designers how the fields should be named, after all they won't give any use to them, it's you (or the developer in turn) who will deal with them. Besides, using underscores (or any other space-replacement) anyone knows beforehand what the text displayed will be, and any special combination of lower/upper-case letters it's preserved. Anyway, right now it seems this is something we can't depend on, so let's refine the expression a little. Oh, and I was refering to the same problem with fields such as MyURL. I've changed a little the pattern, now it would say ignore the initial lower-case letters and spaces (if any of those) and add a space before any upper-case wich is not preceeded by an upper-case, and also those upper-case followed by a lower-case, so it now would look like $rex_initial = '/^[a-z]*\s*/X'; $rex_upper = '/(?![A-Z])(?=[A-Z])|(?=[A-Z][^A-Z])/X'; $text= preg_replace($rex_initial, '', preg_replace($rex_upper, ' ', $name) ); I think that solves the problem with the previous one. But I'd also like to point out that most of us (you included, if I understood right) seem to agree that this shouldn't be the first option, but something simplier --this is more like a patch than a feature ;) Good luck with the designers :) [/snip] You're correct, this shouldn't be the first option. Right now the designers are not under my control as they are outsourced and working with a set of specs created by someone who is/was no longer here when I got here (for good reason and this kind of thing is but one of those reasons). I am working to get designers on staff (and they will work for me), but until that point I have to work with what I have as the business is approaching launch and we really don't have time to go back and rework existing forms, etc. So, being the good systems guy that I am, I try to get it where everyone can work together with as little hassle as possible. We had worked this same problem on this same list about a year ago, so I knew that there was an answer, I just couldn't find it. Thanks to your truly elegant solution I have made developer world much happier this afternoon. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting hexadecimal string
On Sun, March 27, 2005 9:09 pm, Ashley M. Kirchner said: Short (possibly simple) question: How do I convert a hexadecimal string back into it's ascii representation? http://php.net/hex2dec -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Converting a string into ASCII and a bit more - newbie
Hi Klaus, Thanks you very much both for your quick reply and guidance. Yes, it now works as it should. I have a few further questions all related to the subject if you wouldn't mind. One is: how can I do the following (sort of maths) with a secondary string of ascii values i.e. 25203030 with this result string from the first operation (65666768697071727374) should be processed as (65+25)(66+20)(67+30)(68+30)(69+25)(70+20)(71+30)(72+30)(73+25)(74+20) So it actually is a nested loop but I am clueless how to accomplish this in PHP. Then finally I will convert the resulting ascii values string back into chr's. I think I know how to do this. (Finally). Thanks again for your time and help. Alp -Original Message From: Klaus Reimer- Alp wrote: $x=1 while ($x=strlen($string)) { $holder = ord(substr($string, $x, 1)); $result = $result . $holder; } and failed since it takes ages to process and does not really return a proper value/result but repetitive number such as 1.. I think you forgot to increment $x. Add an $x++ at the end of your loop and it works. And by the way: It's better to write $result .= $holder if you want to append a string to another. That's shorter and (more important) faster. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting a string into ASCII and a bit more - newbie
This ought to work: ?php $string = 'ABCDEFGHIJ'; $chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); for ($i = 0; $i count($chars); $i++) { $chars[$i] = ord($chars[$i]); //$chars[$i] = ord($chars[$i]) + 10; } $string = implode('', $chars); ? On Sun, 2004-11-14 at 22:32, Alp wrote: Hi, My question could have quite stright forward answer or the question itself might be silly but being a newbie, I'll ask it anyway. First I am trying to convert each character in a string into their respective ASCII codes and then keep these again in a string. Such as: string : ABCDEFGHIJ, expect to see in the result : 65666768697071727374 Then I would like to further manipulate this result with some math, say add 10 to each pair (the ascii code) so the new result becomes: 75767778798081828384 For my first attempt I tried: $x=1 while ($x=strlen($string)) { $holder = ord(substr($string, $x, 1)); $result = $result . $holder; } and failed since it takes ages to process and does not really return a proper value/result but repetitive number such as 1.. I have also tried a 'for' example I found which failed as well. I truely hope an expert here could show me some light and point me in the right direction. I have 2 sets installed on my PC as PHPDEV423 and XAMPP 1.4.9 (set to use php4) and it fails in both. Thanks in advance, Alp P.S.: I hope I have posted this in the correct NG -- Regards, Matthew Fonda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting a string into ASCII and a bit more - newbie
Thanks Matthew, Got it going finally. Would you be able to help in my further question? Alp Matthew Fonda [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] This ought to work: ?php $string = 'ABCDEFGHIJ'; $chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); for ($i = 0; $i count($chars); $i++) { $chars[$i] = ord($chars[$i]); //$chars[$i] = ord($chars[$i]) + 10; } $string = implode('', $chars); ? On Sun, 2004-11-14 at 22:32, Alp wrote: Hi, My question could have quite stright forward answer or the question itself might be silly but being a newbie, I'll ask it anyway. First I am trying to convert each character in a string into their respective ASCII codes and then keep these again in a string. Such as: string : ABCDEFGHIJ, expect to see in the result : 65666768697071727374 Then I would like to further manipulate this result with some math, say add 10 to each pair (the ascii code) so the new result becomes: 75767778798081828384 For my first attempt I tried: $x=1 while ($x=strlen($string)) { $holder = ord(substr($string, $x, 1)); $result = $result . $holder; } and failed since it takes ages to process and does not really return a proper value/result but repetitive number such as 1.. I have also tried a 'for' example I found which failed as well. I truely hope an expert here could show me some light and point me in the right direction. I have 2 sets installed on my PC as PHPDEV423 and XAMPP 1.4.9 (set to use php4) and it fails in both. Thanks in advance, Alp P.S.: I hope I have posted this in the correct NG -- Regards, Matthew Fonda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting a string into ASCII and a bit more - newbie
Alp wrote: $x=1 while ($x=strlen($string)) { $holder = ord(substr($string, $x, 1)); $result = $result . $holder; } and failed since it takes ages to process and does not really return a proper value/result but repetitive number such as 1.. I think you forgot to increment $x. Add an $x++ at the end of your loop and it works. And by the way: It's better to write $result .= $holder if you want to append a string to another. That's shorter and (more important) faster. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting a string to formatted html
Ian, PLEASE search the archives before asking the list -- this question is asked every couple of days, which is quite frustrating. See http://au.php,net/nl2br Justin French On Monday, October 27, 2003, at 09:15 PM, Ian Gray wrote: Hi all, I know this can be done somehow but I am not sure. I have a form being submitted to a php file and I wanted a textfield to be converted to formatted html. At the moment none of the line breaks are being submitted and inverted commas have slashes. I know the slashes can be removed using stripslashes function. I thought line breaks would come through with \n but that isn't being transmitted over the form. Can anyone help? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php