NameSilo

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

Spaceship Spaceship
Watch
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
Can you show the script you are using? That shouldn't happen..
 
0
•••
I haven't seen your script, but I have a feeling that you should use & instead of simply "&".
 
0
•••
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
•••
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
•••
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
•••
PHP:
<?php

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

?>
 
0
•••
Or you could use its UTF symbol...dont recall it at the moment (i.e. a space is %20)
 
0
•••
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
•••
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
•••
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
•••
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
•••
vbSEO just lost a lot of potential customers...
 
0
•••
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
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back