Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

[Resolved] How to handle "&" symbol in PHP

Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
Watch

newsiness

VIP Member
Impact
49
How to handle "&" symbol in PHP

I input an url for example
xxxxxx.com/xxxxxx/content.asp?y=2006&dt=1209&pub=xxxxxxx&sec=xxxxxxx&pg=mh_01.htm
into my php script,
but when i print the output, it shows me this
xxxxxx.com/xxxxxx/content.asp?y=2006

I am unable to print after the "&" symbol. Any idea?

Really appreciate for your help....:)
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Can you show the script you are using? That shouldn't happen..
 
0
Close
I haven't seen your script, but I have a feeling that you should use & instead of simply "&".
 
0
Close
Thank you for your reply...:)

My php script is as shown below:

PHP:
<?php $searchterm = $_GET['p'];
$searchterm = stripslashes($searchterm); 
$searchterm = urlencode($searchterm);
?>
<?php

if ($p) {

    $p = str_replace(" ", "+", $HTTP_GET_VARS['p']);
    
    $p = stripslashes($p);
    
    $abc = $_GET['p'];
    
    $abc = stripslashes($abc);
        
echo "<b>$abc</b></br>";

echo "<b>$p</b>";

?>
<?php } ?>

I save this script as sample.php and located at http://www.newsiness.com/sample.php

The usage of this script is as shown below:

Let's say i would like to print this url xxxxxx.com/xxxxxx/content.asp?y=2006&dt=1209&pub=xxxxxxx&sec=xxxxxxx&pg=mh_01.htm

Then i point to this url http://www.newsiness.com/sample.php...&dt=1209&pub=xxxxxxx&sec=xxxxxxx&pg=mh_01.htm

The output should show me this xxxxxx.com/xxxxxx/content.asp?y=2006&dt=1209&pub=xxxxxxx&sec=xxxxxxx&pg=mh_01.htm instead of xxxxxx.com/xxxxxx/content.asp?y=2006

Any idea? Thanks in advance!!!
 
0
Close
You need to urlencode() it before passing it into $p. The URL has p= and then &dt= which it thinks is a new variable.
 
1
Close
Dan said:
You need to urlencode() it before passing it into $p. The URL has p= and then &dt= which it thinks is a new variable.

Hi Dan,

Can you please show me how to add this urlencode() into my php script as i am not so familiar with PHP programming. Thank you for your help...
 
0
Close
PHP:
<?php

$output = '';
$i      = 1;
foreach ($_GET as $key=>$value) {
	if ($i != 1) $output .= '&'.$key.'=';
	$output .= $value;
}
echo $output;

?>
 
0
Close
Or you could use its UTF symbol...dont recall it at the moment (i.e. a space is %20)
 
0
Close
Dan said:
PHP:
<?php

$output = '';
$i      = 1;
foreach ($_GET as $key=>$value) {
	if ($i != 1) $output .= '&'.$key.'=';
	$output .= $value;
}
echo $output;

?>

Dan, I save the php script above to sample2.php and located at http://www.newsiness.com/sample2.php

With this sample2.php script,

http://www.newsiness.com/sample2.ph...&dt=1209&pub=xxxxxxx&sec=xxxxxxx&pg=mh_01.htm

the ouput i get is xxxxxx.com/xxxxxx/content.asp?y=20061209xxxxxxxxxxxxxxmh_01.htm

still do not work perfectly...suppose to be
xxxxxx.com/xxxxxx/content.asp?y=2006&dt=1209&pub=xxxxxxx&sec=xxxxxxx&pg=mh_01.htm

Please guide...
 
0
Close
Thanks Dan for this piece of PHP...:)

PHP:
<?php 
$url = '';
    foreach($_GET as $key => $value) {
        $url .= '&'.$key.'='.$value;
    }
    
    if(!empty($url)) {
        $url = substr($url, 1);
        echo '<a href="http://www.newsiness.com/sample.php?'.urlencode($url).'">'.MouseOverHere.'</a>';
?><?php } ?>

I have save this php as sample4.php and located at http://www.newsiness.com/sample4.php

The working url is here
http://www.newsiness.com/sample4.ph...&dt=1209&pub=xxxxxxx&sec=xxxxxxx&pg=mh_01.htm

It gives the correct output...:) Thank you Dan for the effort...Rep added...
 
0
Close
Google news for PHP

Hi,

Good news from google for Programming.....

Now google will index all the dynamic url's like they index our static url's because

they have come with an update stating they will accept all the strings one of

the example is & etc... if you need any details then you can see the

google guidelines....

This update came last month....
 
0
Close
rohoni said:
Hi,

Good news from google for Programming.....

Now google will index all the dynamic url's like they index our static url's because

they have come with an update stating they will accept all the strings one of

the example is & etc... if you need any details then you can see the

google guidelines....

This update came last month....
That's certainly good news. :D

So, no need for Mod Rewrite on forums etc...:)
 
0
Close
vbSEO just lost a lot of potential customers...
 
0
Close
rohoni said:
Hi,

Good news from google for Programming.....

Now google will index all the dynamic url's like they index our static url's because

they have come with an update stating they will accept all the strings one of

the example is & etc... if you need any details then you can see the

google guidelines....

This update came last month....

Thanks for the update...
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back