Jump to content

Parsing a URL and unexpected T_ENCAPSED_AND_WHITESPACE


wright67uk

Recommended Posts

Can anybody help me to echo a url?

 

Id like to have

 

http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|SG1+4PP&sensor=false

 

but to have the postcode as a variable which has been fetched from mysql

 

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
  include($_SERVER['DOCUMENT_ROOT'].'/include/db.php');
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
-->
</style>
<link href="header.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="banner">
<div id="bannerleft"></div>
<div id="logo"></div>
<div id="bannerright"><div id="navbar" title="">	 
			<div id="b1"><p class="centre"><a href="index.html">Directory</a></p></div>
    				<div id="b2"><p class="centre"><a href="business.html">Add Your Business</a></p></div>
                        	 	<div id="b3"><p class="centre"><a href="contact.html">Contact Us</a></p></div>
    	                    </div><!-- end of navbar-->
</div><!--end of bannerright-->
</div><!-- end of banner-->
<div id="listhold">
<?php 
$subtype = $_GET['subtype'];

echo "<h1>$subtype</h1>";
$result	 = mysql_query("SELECT name, phone, email, WebAddress, postcode FROM business WHERE subtype ='$subtype' AND confirmed ='Yes' ORDER BY name");
echo mysql_error();
while($row = mysql_fetch_array($result))
{
echo $row['name'] . "<br>";
echo $row ['phone'] . "<br>";
echo $row['email'] . "<br>";
echo $row['WebAddress'] . "<br>";
echo $row['postcode'] . "<br>" . "<br>";
echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',$row['postcode'])&sensor=false'>";
}

?>
</div>
</body>
</html>

 

The above returns an error;

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Link to comment
Share on other sites

For that error, forum highlighting software (such as the one used to highlight the code in your post) will often give a bit, giant, red-colored clue as to where the problem lies.

 

In this case it shows where a problem is.

 

What line number does the error message refer to? And did you post the exact code?

Link to comment
Share on other sites

//notice the following line:
echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',$row['postcode'])&sensor=false'>"; //<-the brackets around $row['postcode'] doesn't look right.

//Now, notice this line:
echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',{$row['postcode']})&sensor=false'>"; //<-brackets look right now.  This is because of how php handles array values in double quoted strings.
//you can either break out of the string, or you can enclose them in curly braces, or you can just not put the key inside of single quotes.  Any of the 3 will work.

Link to comment
Share on other sites

Change:

echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',$row['postcode'])&sensor=false'>"; //<-the brackets around $row['postcode'] doesn't look right.

 

To:


//Now, notice this line:
echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|".str_replace(' ','+',$row['postcode'])."&sensor=false'>";

Link to comment
Share on other sites

Change:

echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',$row['postcode'])&sensor=false'>"; //<-the brackets around $row['postcode'] doesn't look right.

 

To:


//Now, notice this line:
echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|".str_replace(' ','+',$row['postcode'])."&sensor=false'>";

 

^correct, way to many hours looking at pixels.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.