6 Replies - 1081 Views - Last Post: 22 January 2009 - 11:15 AM Rate Topic: -----

#1 tremtie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-January 09

Echo in php using single quotes

Posted 19 January 2009 - 03:36 AM

Hi all, thanks to anyone who takes the time to help. The problem I have is quite simple. I am using an echo command in php, with single quotes.

Here is the relevant line:

echo '<markers>';



My understanding is that this should use the literal string included in the single quotes without parsing. Yet, I get no output from this line.

If replace that line with a string without ">" or "<" characters, it shows up fine. For example, the following works fine:

echo 'test';



Also, when there is no content in between the brackets, the echo also works, as in:

echo '<>';



Yet, if I put anything at all between them, I get no output at all from this line. I've tried using escape characters as well, it doesn't solve the problem.

I am using godaddy as my host, I don't know if it's relevant to this, but I've heard there can be weird problems with them.

Thanks!

I've posted the entire code below, with password and database name redacted of course, for those who are interested. I am in the middle of development, so that's why it's a bit disorganized.


<?php

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",''',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

$con = mysql_connect("databaseIPHere","databaseNameHere","passwordHere");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Execute query
mysql_query($sql,$con);

mysql_select_db("databaseNameHere", $con);

$result = mysql_query("SELECT `Stores`.`name` FROM Stores
WHERE (`Stores`.`name` LIKE '%pizza%')");

// header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

//echo 'testing 1 2 3';

// Iterate through the rows, printing XML nodes for each
while ($row = mysql_fetch_array($result)){
  // ADD TO XML DOCUMENT NODE

//   echo "<td>" . $row['name'] . "</td>";

//  echo "<marker ";
//  echo 'name="' . parseToXML($row['name']) . '" ';
//  echo 'address="' . parseToXML($row['address']) . '" ';
echo 'name="' . $row['name'] . '" ';
//  echo address="' . $row['address'] . '";
//  echo lat="' . $row['lat'] . '" ';
//  echo lng="' . $row['lng'] . '" ';
//  echo type="' . $row['type'] . '" ';
//  echo />';
}

// End XML file
 echo '</markers>';

mysql_close($con);
?>



This post has been edited by tremtie: 19 January 2009 - 03:38 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Echo in php using single quotes

#2 BenignDesign  Icon User is online

  • holy shitin shishkebobs
  • member icon




Reputation: 6011
  • View blog
  • Posts: 10,439
  • Joined: 28-September 07

Re: Echo in php using single quotes

Posted 19 January 2009 - 06:51 AM

Moved to PHP.

Ok, the reason you're not getting anything to display is most likely due to your browser interpreting your

echo '<markers>';



as an HTML tag. try

echo '&lt;markers&gt;';



and see if it works for you.
Was This Post Helpful? 0
  • +
  • -

#3 rmccarter721  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 139
  • Joined: 10-September 07

Re: Echo in php using single quotes

Posted 19 January 2009 - 06:58 AM

I believe if you change the line from

echo '<markers>';


to

echo '&lt;markers&gt;';


You should be ok
Was This Post Helpful? 0
  • +
  • -

#4 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: Echo in php using single quotes

Posted 19 January 2009 - 10:58 AM

just a side note, php has some amazing xml abilities. I know it's hard to drop something when you have an idea to learn something totally new, I hated learning xml processing myself, but afterward it was worth it.

Two things to look at:
SimpleXML
DOM
Was This Post Helpful? 0
  • +
  • -

#5 rmccarter721  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 139
  • Joined: 10-September 07

Re: Echo in php using single quotes

Posted 19 January 2009 - 11:44 AM

I could of swore BenignDesign's post just said Topic Moved earlier..

hmm..
Was This Post Helpful? 0
  • +
  • -

#6 BenignDesign  Icon User is online

  • holy shitin shishkebobs
  • member icon




Reputation: 6011
  • View blog
  • Posts: 10,439
  • Joined: 28-September 07

Re: Echo in php using single quotes

Posted 19 January 2009 - 12:33 PM

lol... it did say "topic moved"...

And I edited it to give help and by the time I reposted, you had already posted the same thing.

Lo siento, senor.
Was This Post Helpful? 0
  • +
  • -

#7 kiwi2  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 178
  • Joined: 16-September 08

Re: Echo in php using single quotes

Posted 22 January 2009 - 11:15 AM

htmlentities ? Convert all applicable characters to HTML entities
Description
string htmlentities ( string $string [, int $quote_style [, string $charset [, bool $double_encode ]]] )

This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

If you're wanting to decode instead (the reverse) you can use html_entity_decode().
Parameters

string

The input string.
quote_style

Like htmlspecialchars(), the optional second quote_style parameter lets you define what will be done with 'single' and "double" quotes. It takes on one of three constants with the default being ENT_COMPAT:
quick dip at php.net, produced the above solutions, but I could'nt agree more with the look into simple XML that someone suggested earlier.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1