LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-03-2008, 02:18 PM   #1
stranger_6_7
LQ Newbie
 
Registered: Nov 2006
Posts: 24

Rep: Reputation: 15
string with dollar symbol in url parameters in php


Hi,

I am writing a script in php where the following url when opened in a browser returns an xml.

http://localhost/search?searchid=GR$GrIF0BYUcRqSIWXRiPA&c=10&_sid_=23-_IK8gOFlgun2WqLysOvC

when I try to open the url using any functions fopen or curl in php,
the xml is not returned. The problem I found out was the searchid string in the above url i.e searchid=GR$GrIF0BYUcRqSIWXRiPA.
It has a "$" character in the string .So php is interpreting the "$" sign as new variable rather than a string and returning improper results.

How can I solve this problem?

Please help asap.

Thanks for the help in advance.

Regards,
Stranger.
 
Old 09-03-2008, 02:45 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Not sure how you're getting the string, but:

$foo = "some$string";

is not the same as

$foo = 'some$string';

as can be seen by:

PHP Code:
$foo "some$string";
echo 
"$foo\n";
$foo 'some$string';
echo 
"$foo\n"
which outputs:
Code:
some
some$string
Otherwise, if you're forming the string inside php, you can escape the $, which will also work.
 
Old 09-03-2008, 02:56 PM   #3
stranger_6_7
LQ Newbie
 
Registered: Nov 2006
Posts: 24

Original Poster
Rep: Reputation: 15
Thanks for the fast reply..

Actually This is what I am doing.

function Results($SessionId,$SearchId)
{
global $flightData;
echo "<BR>";
$flighturl = "http://www.k.com/s/basic/flight?searchid=$SearchId&c=10&apimode=1&_sid_=$SessionId";
echo $flighturl;
echo "<BR>";
echo "<a href=$flighturl>Click on the URL to see Flight results</a>";
MagicParser_parse($flighturl,"flightHandler","xml|SEARCHRESULT/");

}

The $SessionId and $SearchId will have values that are randomly generated by the API; For Ex:

Session Id is 14-fqRZ8_QO4ScJF$RuXvdR
Search Id is eu$iI8$XOKQiTi8_p1DT_Q

both of them may randomly have $ string randomly appearing every time I call the API.

So I am unable to send the exact sessionid value as
 
Old 09-03-2008, 03:07 PM   #4
stranger_6_7
LQ Newbie
 
Registered: Nov 2006
Posts: 24

Original Poster
Rep: Reputation: 15
Thanks for the fast reply..

Actually This is what I am doing.

function Results($SessionId,$SearchId)
{
global $flightData;
echo "<BR>";
$flighturl = "http://www.k.com/s/basic/flight?searchid=$SearchId&c=10&apimode=1&_sid_=$SessionId";
echo $flighturl;
echo "<BR>";
echo "<a href=$flighturl>Click on the URL to see Flight results</a>";
MagicParser_parse($flighturl,"flightHandler","xml|SEARCHRESULT/");

}

The $SessionId and $SearchId will have values that are randomly generated by the API; For Ex:

Session Id is 14-fqRZ8_QO4ScJF$RuXvdR
Search Id is eu$iI8$XOKQiTi8_p1DT_Q

both of them may randomly have $ string randomly appearing every time I call the API.

So I am unable to send the exact sessionid value as generated by the API
 
Old 09-03-2008, 03:19 PM   #5
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
hmm... having a hard time replicating.

PHP Code:
function printer($t1,$t2) {
  
$thing "http://foo.com/$t1/$t2/";
  echo 
"$thing\n";
}

$s1 'some$string';
$s2 'other$thing';

printer($s1,$s2); 
outputs:
Code:
http://foo.com/some$string/other$thing/
works in both a browser and with the CLI.

Maybe the '$' is not the problem? If you echo out the parms you're passing to that func, do they appear to be missing everything after the '$'?

Maybe php is trying to return an xml file but is not explicitly setting an xml header?
PHP Code:
header("Content-Type: text/xml"); 

Last edited by BrianK; 09-03-2008 at 03:25 PM.
 
Old 09-03-2008, 03:36 PM   #6
stranger_6_7
LQ Newbie
 
Registered: Nov 2006
Posts: 24

Original Poster
Rep: Reputation: 15
I did the following;

$SearchId = eu$iI8$XOKQiTi8_p1DT_Q; // this string is generated at runtime from an xml

I am retrieving that xml value and storing in $SearchId variable.



when I am changing this to
$ksid = '$SearchId';

echo $ksid:

output : '$SearchId';

$url = http://foo.com/searchId=$ksid //i.e http://foo.com/searchId='$SearchId' --- error



when I am changing this to
$ksid = "'".$SearchId ."'";
echo $ksid;

output : 'eu$iI8$XOKQiTi8_p1DT_Q';


$url = http://foo.com/searchId=$ksid // http://foo.com/searchId='eu$iI8$XOKQiTi8_p1DT_Q' --- error


I need this :


$url = http://foo.com/searchId=$ksid //http://foo.com/searchId=eu$iI8$XOKQiTi8_p1DT_Q

Thanks for the help..

Awaiting your reply

Best Regards
 
Old 09-03-2008, 03:58 PM   #7
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
PHP Code:
$SearchId 'eu$iI8$XOKQiTi8_p1DT_Q';
$ksid $SearchId;
echo 
$ksid;
echo 
"\n";
$url "http://foo.com/searchId=$ksid";
echo 
$url;
echo 
"\n"
outputs:
Code:
eu$iI8$XOKQiTi8_p1DT_Q
http://foo.com/searchId=eu$iI8$XOKQiTi8_p1DT_Q
 
Old 09-03-2008, 04:21 PM   #8
stranger_6_7
LQ Newbie
 
Registered: Nov 2006
Posts: 24

Original Poster
Rep: Reputation: 15
Thank you so much. I got it.

I am facing one more strange problem.Can you please help me in this.

How can I write an xml from an url to a file using php.

When I open the url it is showing the xml data perfectly.

But when I use curl or fopen to grab the xml data... It is not grabbing that xml.

How can i do this.

Thanks for the help
 
Old 09-03-2008, 04:23 PM   #9
stranger_6_7
LQ Newbie
 
Registered: Nov 2006
Posts: 24

Original Poster
Rep: Reputation: 15
The url doesnt have a XML file.. It is a API that returns an XML on opening the url in browser
and I have to grab that xml data to display them in html.

Thank you
 
Old 09-03-2008, 04:42 PM   #10
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
How are you displaying the xml? a simple echo? Are you sending xml headers? For instance, if I leave out the "header(...)" line, the following will not return proper xml data, even though if you view the source of the resulting page, it's perfect xml.

PHP Code:
<?php
header
("Content-Type: text/xml");
$f file_get_contents("./sheldon-bk.xml");
echo 
$f;
?>
to reiterate... without the "header()" line, the above does not return proper a proper xml document even though the text it does return is proper xml. With the "header()" line, it works perfectly.


edit:
hmm... re-read your question. I don't think I answered it.
Sorry, I don't have a good answer, but I'll leave this here for the record.

Last edited by BrianK; 09-03-2008 at 04:45 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing parameters in string in C shifter Programming 8 04-11-2008 09:01 AM
£ symbol and PHP richlawson Programming 7 02-01-2006 05:51 AM
Missing PHP parameters on apache2 eplanamente Linux - Software 2 12-29-2005 05:01 PM
Regular expression to match a valid URL string vharishankar Programming 13 07-21-2005 09:17 PM
PHP - passing multiple parameters jacksmash Programming 1 11-25-2003 10:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration