+ Post New Thread
Results 1 to 6 of 6
Coding Thread, PHP Conditional Replace in Coding and Web Development; Need a little help, i'm by now means literate in PHP but here goes: Code: <?php $tag=$_GET['tag']; if($_GET['tag']==''){ $tag = ...
  1. #1

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29

    PHP Conditional Replace

    Need a little help, i'm by now means literate in PHP but here goes:

    Code:
    <?php
    
    
    $tag=$_GET['tag'];
    
    if($_GET['tag']==''){
    
    $tag = 'Search...';}
    
    if (!isset($_GET['maxpages']))
    {
    $max_pages = 20;
    }else
    {
    $max_pages = $_GET['maxpages'];
    }
    if ($max_pages > 50)
    {
    die("No way am i doing more than 50 pages. Sorry mate.");
    }
    ?>
    I use a form to take $tag and stick it on the end of a url:

    http://search.twitter.com/search.atom?&q={$tag}

    Its basically a Twitter search script, the trouble i having is if $tag contains a #, kinda vital to a twitter search.

    I think whats happening is this:

    $tag = #edugeek

    - Twitter Search%23edugeek

    I think twitter needs to get #edugeek not %23edugeek

    How can I change my script so that if $tag starts with # or contains # it is correctly sent to twitter?

    To test I replaced %23 to # in the browser and it works, just need the script to do it now!

  2. #2
    dwhyte85's Avatar
    Join Date
    Mar 2009
    Location
    Berkshire
    Posts
    1,219
    Thank Post
    159
    Thanked 147 Times in 132 Posts
    Rep Power
    103
    PHP: urldecode - Manual

    UrlDecode, this will change %23 to # within your string


    PHP Code:
    <?php


    $tag 
    urldecode($_GET['tag']);// should work or, $tag = $_GET['tag'];$tag = urldecode($tag);

    if($_GET['tag']==''){

    $tag 'Search...';}

    if (!isset(
    $_GET['maxpages']))
    {
    $max_pages 20;
    }else
    {
    $max_pages $_GET['maxpages'];
    }
    if (
    $max_pages 50)
    {
    die(
    "No way am i doing more than 50 pages. Sorry mate.");
    }
    ?>
    Last edited by dwhyte85; 19th May 2009 at 06:38 PM.

  3. #3

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29
    Superb, thats exactly what I needed....

    Well almost, I got the problem wrong... I needed to Encode the # not decode

    Ta!

  4. #4

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Quote Originally Posted by danIT View Post
    Superb, thats exactly what I needed....

    Well almost, I got the problem wrong... I needed to Encode the # not decode

    Ta!
    That'll be PHP: urlencode - Manual then...

  5. #5

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29


    --

    Sidenote:

    I also generate a .csv of the search to download, anyone know how I might store this on the server once generated?

    A colleage did tell me the name of a function but cant for the life of me remember? Think it began with S?

  6. #6

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Quote Originally Posted by danIT View Post
    Sidenote:

    I also generate a .csv of the search to download, anyone know how I might store this on the server once generated?

    A colleage did tell me the name of a function but cant for the life of me remember? Think it began with S?
    Probably fopen(), fwrite() and fclose().

SHARE:
+ Post New Thread

Similar Threads

  1. Replace ID instead of CLASS
    By danIT in forum Coding
    Replies: 3
    Last Post: 13th March 2009, 11:26 PM
  2. [MS Office - 2003] Access - Conditional Macros
    By garethedmondson in forum Office Software
    Replies: 5
    Last Post: 27th January 2009, 12:06 AM
  3. Conditional formatting help needed
    By Jobos in forum How do you do....it?
    Replies: 3
    Last Post: 3rd June 2008, 01:58 PM
  4. Time to replace?
    By cgiuk in forum Hardware
    Replies: 11
    Last Post: 24th January 2008, 08:27 AM
  5. Help with conditional formatting
    By randle in forum Windows
    Replies: 3
    Last Post: 25th October 2007, 01:20 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •