Blog

Comments Off

Make Request Url with urlencode function

Author: webulent, Posted On: February 28th, 2012, In: Php

< ?php
class makeRequestUrl{
	public $querystring=null;
	public $params=null;

	public function takeIt(){
		$querystring = null;
		foreach ($this->params as $name => $value){
		  $querystring = $name . '=' . urlencode($value) . '&' . $querystring;
		}	
		$this->querystring = $this->cutLastChar($querystring);	
	}
	public function cutLastChar($querystring){
		// Cut the last '&'
		$querystring=substr($querystring, 0, strlen($querystring)-1);
		return htmlentities($querystring);
	}
	public function returnIt(){
		return $this->querystring;
	}
}

$example = new makeRequestUrl;
$example->params = array('name' => 'post','action' => 'comment_count');
$example->takeIt();
echo 'Output: '.$example->returnIt();  //Output: action=comment_count&name=post
?>