SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow How do you convert this?

    I have these value save in the MySQL table using PHP.

    doug%2B

    and this below,

    doug%252B75ogud%252B

    how do you convert those into normal string? using PHP how?

    What command should i use.

    Thank you.

  2. #2
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow

    anyone can decode those?


    thanks in advance.

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by solidcodes View Post
    anyone can decode those?
    Try urldecode()
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  4. #4
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I already tried it and this is what i get,

    doug+
    doug%2B75ogud%2B

    The + sign and %2B is not part of the string.

    If decoded properly it suppose to show like these below,

    doug
    doug75ogud

    Anyone can decode these properly?

    Thank you.

  5. #5
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How exactly you have gotten this kind of strings?

  6. #6
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    actually the value 'doug%2B' is the firstname it came from a form,
    here is the codes,
    Code:
    $objPaypal-> lastName = urlencode($_POST['lastname']);
    $objPaypal-> lastName = strtolower($objPaypal->lastName);
    $objPaypal-> lastName = urlencode($objPaypal->lastName);
    and then the username 'doug%252B75ogud%252B' is came from a function formula,
    here is the codes for that,
    Code:
    	function createUser() {
    		//fetch username
    		$userFirst = $this->firstName;
    	
    		//create random user
    		$userNumber = rand(10, 99);
    		
    		//fetch lastname then randomize.
    		$userLast = str_shuffle($userFirst);
    		
    		//concantenate them.
    		$tmpUserName = $userFirst . $userNumber . $userLast;
    		$this->userName = urlencode($tmpUserName);
    		
    	  //fetch from member table the username
    		$query = "SELECT username FROM member WHERE username='$tmpUserName'";
    		$result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error());
    		$row = mysql_fetch_array($result);
    		$dbUserName = $row['username'];
    
    		if($dbUserName == $this->userName) {
    			//this function again.
    			$this->createUser();
    		} else {
    			//store username into variable
    			$this->userName = urlencode($tmpUserName);
    		}
    	}

    Thanks in advance.

  7. #7
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by solidcodes View Post
    Code:
    $objPaypal-> lastName = urlencode($_POST['lastname']);
    $objPaypal-> lastName = strtolower($objPaypal->lastName);
    $objPaypal-> lastName = urlencode($objPaypal->lastName);
    Why do you do a urlencode twice?

  8. #8
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    okay lets assume i already remove the 2nd urlencode.

    how about the 2nd codes for the username?

    thanks.

  9. #9
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This function creates unique username based on user input right? And then compares the created temporary username to usernames in database. If it does not exist it puts it in variable and if it exists it runs again the random username creation process. So if I got it right the user input from the form is first urlencoded (this could be undone) but after str_shuffle I don't think that can be anymore decoded anyhow.

  10. #10
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $str 'doug%252B75ogud%252B';
    $str urldecode($str); // prints 'doug%2B75ogud%2B'
    var_dump($str); // prints 'doug%2B75ogud%2B'
    $str urldecode($str);
    var_dump($str); // prints 'doug+75ogud+'
    $str str_replace('+'' '$str);
    var_dump($str); // prints 'doug 75ogud ' 
    In the last example there is the firstname/username, random number, and finally the firstname/username run through str_shuffle. It is very likely your double urldecode messed it up for you to understand.


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
  •