Welcome Guest, Not a member yet? Register   Sign In
[Solved] Automatically replace the first & with a ? question mark.
#1

(This post was last modified: 04-05-2018, 11:54 PM by wolfgang1983.)

I have this code below which generates a query string for my url.

But I would like to know is there away that it could automatically replace the first & with a ? question mark.


PHP Code:
$url '';

if (
$this->input->get('directory')) {
 
  $pos strrpos($this->input->get('directory'), '/');

 
  if ($pos) {
 
     $url .= '&directory=' urlencode(substr($this->input->get('directory'), 0$pos));
 
  }
}

if (
$this->input->get('target')) {
 
   $url .= '&target=' $this->input->get('target'); 
}

if (
$this->input->get('thumb')) {
 
   $url .= '&thumb=' $this->input->get('thumb'); 



$data['parent'] = base_url('image_manager' $url); 
Reply
#2

http://php.net/manual/en/function.substr.php
PHP Code:
$url '?'.substr($url1); 
Reply
#3

(This post was last modified: 04-05-2018, 11:55 PM by wolfgang1983.)

Thanks to all who helped working solution

PHP Code:
$find '&';
$replace '?';

$result preg_replace("/$find/"$replace$url1);

echo 
$result
Full
PHP Code:
$url '';

if (
$this->input->get('directory')) {
 
  $pos strrpos($this->input->get('directory'), '/');

 
  if ($pos) {
 
     $url .= '&directory=' substr($this->input->get('directory'), 0$pos);
 
  }
}

if (
$this->input->get('target')) {
 
   $url .= '&target=' $this->input->get('target'); 
}

if (
$this->input->get('thumb')) {
 
   $url .= '&thumb=' $this->input->get('thumb'); 



$data['parent'] = base_url('image_manager' $url); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB