SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    empty string output

    First of all, I have an input
    Code:
    <input name="groupid" format="*m" size="8" title="room"/><br/>
    	<a title="enter" href="chat.php?groupid=$(groupid)&amp;sid=<?echo $sid ?>">enter room</a><br/>
    where the user can change the groupid for the chatroom, when the user input is a word everything is working fine, but when the user leave spaces and sends and empty string for the groupid like this,
    Code:
    http://whatever.com/wml/chat.php?groupid=%20&sid=db0f88d47c939ddf5cbe4622a493751e
    the groupid is %20

    this is part of the chat.php
    PHP Code:
    if(isset($_GET['groupid']) AND ($_GET['groupid'] !=='')){
    $groupid $_GET['groupid'];
    $groupid trim($groupid);
    $groupid mb_strtolower($groupid);
    }else{
    $groupid str_replace("%20""chat" "$groupid");
    $groupid "chat";

    and its not working the first time, only after refresh, how can I avoid the %20 space from the output?

  2. #2
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried urldecode?
    $groupid = trim(urldecode($groupid));

  3. #3
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not working, sorry. Is there any other way to strip out the %20 from the output?
    Last edited by Ernie1; Nov 26, 2005 at 04:32.

  4. #4
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anybody give me a solution?

  5. #5
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:
    PHP Code:
       if(isset($_GET['groupid']) AND ($_GET['groupid'] !== '' && $_GET['groupid'] != '%20'])){ 
      
    $groupid $_GET['groupid']; 
      
    $groupid trim($groupid); 
      
    $groupid mb_strtolower($groupid); 
      }else{ 
      
    $groupid "chat"
      } 
    </font></font>

  6. #6
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aamonkey
    try this:
    PHP Code:
       if(isset($_GET['groupid']) AND ($_GET['groupid'] !== '' && $_GET['groupid'] != '%20')){ 
      
    $groupid $_GET['groupid']; 
      
    $groupid trim($groupid); 
      
    $groupid mb_strtolower($groupid); 
      }else{ 
      
    $groupid "chat"
      } 
    It's the same output and works only after the refresh.

  7. #7
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops--forgot to change to %20 to a space:

    PHP Code:
      if(isset($_GET['groupid']) AND ($_GET['groupid'] !== '' && $_GET['groupid'] != ' '])){ 
       
    $groupid $_GET['groupid']; 
       
    $groupid trim($groupid); 
       
    $groupid mb_strtolower($groupid); 
       }else{ 
       
    $groupid "chat"
       } 

  8. #8
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, this is what I've been looking for.

  9. #9
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was wondering if there is a better way to get rid all these characters like this?

    PHP Code:
    if(isset($_GET['groupid']) AND ($_GET['groupid'] !== '' && $_GET['groupid'] != ' '
    && $_GET['groupid'] != '`' && $_GET['groupid'] != '~' && $_GET['groupid'] != '!'
    && $_GET['groupid'] != '@' && $_GET['groupid'] != '#' && $_GET['groupid'] != '$'
    && $_GET['groupid'] != '%' && $_GET['groupid'] != '^' && $_GET['groupid'] != '&'
    && $_GET['groupid'] != '*' && $_GET['groupid'] != '(' && $_GET['groupid'] != ')'
    && $_GET['groupid'] != '_' && $_GET['groupid'] != '-' && $_GET['groupid'] != '+'
    && $_GET['groupid'] != '=' && $_GET['groupid'] != '|' && $_GET['groupid'] != ':'
    && $_GET['groupid'] != ';' && $_GET['groupid'] != '"' && $_GET['groupid'] != "'"
    && $_GET['groupid'] != '<' && $_GET['groupid'] != '>' && $_GET['groupid'] != ','
    && $_GET['groupid'] != '.' && $_GET['groupid'] != '?' && $_GET['groupid'] != '/'
    && $_GET['groupid'] != '\\')){ 
       
    $groupid $_GET['groupid']; 
       
    $groupid trim($groupid); 
       
    $groupid mb_strtolower($groupid); 
       }else{ 
       
    $groupid "chat"
       } 

  10. #10
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought It would be better to create an alphanumeric function to validate the groupid.

    Can anybody help me create this function?

    Thank you in advance!
    Last edited by Ernie1; Nov 29, 2005 at 14:05.

  11. #11
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I finally found a solution:
    PHP Code:
    if(isset($_GET['groupid']) AND ($_GET['groupid'] !== '' && $_GET['groupid'] != ' ')){ 
       
    $groupid $_GET['groupid'];
    $b=strspnstrtolower($groupid), "abcdefghijklmnopqrstuvwxyz");
           if (
    $b strlen($groupid)) {
                   
    $groupid "chat";

       
    $groupid trim($groupid); 
       
    $groupid mb_strtolower($groupid); 
       }else{ 
       
    $groupid "chat"
       } 
    it might help someone.


Bookmarks

Posting Permissions

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