Irish SEO,  Marketing & Webmaster Discussion

 

HELP :: PHP regular expression question

This is a discussion on HELP :: PHP regular expression question within the Coding Help forums, part of the Webmaster Help category; I have to change the values of several variables passed as a string containing url parameters. But only the "to_" ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-03-2007, 03:15 AM
Frontpage User
 
Join Date: Oct 2006
Posts: 24
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
littleBird will become famous soon enough
Send a message via Skype™ to littleBird
Default HELP :: PHP regular expression question

I have to change the values of several variables passed as a string containing url parameters. But only the "to_" date variables!

"from_yyyy=2006&from_mm=03&from_dd=08&to_yyyy=2007 &to_mm=01&to_dd=08"

Is preg_match the best option?
Can someone give me advice on best way to approach the PCRE expression?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 10-03-2007, 03:25 AM
georgiecasey's Avatar
Member
 
Join Date: Jul 2006
Location: Galway / Ennis
Posts: 277
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
georgiecasey will become famous soon enough
Send a message via ICQ to georgiecasey
Default

Looks easy with preg_replace and an array of strings of each date. But I'm a crappy programmer, I could be wrong.
__________________

My Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 10-03-2007, 12:58 PM
daviddoran's Avatar
Wannabe Geek
Recent Blog: iMSISS
 
Join Date: Aug 2006
Location: Meath, Ireland
Posts: 342
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
daviddoran will become famous soon enough
Default

I think this is the most technically correct way to do it:
Code:
<?php

$output = array();
parse_str( 'from_yyyy=2006&from_mm=03&from_dd=08&to_yyyy=2007 &to_mm=01&to_dd=08', $output );
if( isset($output['to_yyyy']) ){
        //New Year
        $output['to_yyyy'] = '';
}

if( isset($output['to_mm']) ){
        //New Month
        $output['to_mm'] = '';
}

if( isset($output['to_dd']) ){
        //New Day
        $output['to_dd'] = '';
}

$new_str = '';
$i=0;
foreach( $output as $k=>$v )
{
        $new_str .= (($i>0)?('&'):('')) . $k . '=' . $v;
        $i++;
}

echo $new_str;

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 13-03-2007, 10:33 PM
Frontpage User
 
Join Date: Oct 2006
Posts: 24
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
littleBird will become famous soon enough
Send a message via Skype™ to littleBird
Default

DavidDoran, you are a legend. Works a treat and no sight-nor-sign of those presky regular expressions. Yet again I dodge the neccessity to get my hands dirty with the PCRL.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
expression, php, question, regular

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
PHP woes : checking if value is numeric paul Coding Help 9 26-02-2007 02:50 PM
Bandwidth question JamesA Webmaster Discussion 4 28-01-2007 10:56 AM
Joomla question fobby Coding Help 7 05-01-2007 11:02 AM
PHP on windows louie Coding Help 20 22-02-2006 06:25 PM


Sponsored links

Paid On Results


All times are GMT +1. The time now is 04:40 AM.


Powered by: vBulletin Version 3.7.3, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.2.0