Jump to content

How to add single quote instead of double quote?


mark107

Recommended Posts

I'm working on my php as I'm generating to make the xml output.
 
I need some help with my php as I want to add the single quotes in the <programme channel= tag to make it like this:
 
<programme channel='101 ABC FAMILY' start='20140504113000' stop='20140504131000'>

On mine the output show like this:

 

<programme channel="101 ABC FAMILY" start="20140504113000" stop="20140504131000">
 
The problem are lie in this line:
 
$xml .= "
      <programme channel='$my_id $channel' start='$stoptime' stop='$starttime'>";

 

Can you please tell me how i can make the output with the single quotes instead of using double quotes?

Link to post
Share on other sites

Is there any reason why the looks of the document are so super-important for you? XML doesn't care whether it's a single or a double quote. Both delimit attributes, and that's it.

Link to post
Share on other sites

Because it is my script and it is my own work to use so it does bother me!!!

 

so how to add the single quote in the <programme channel= tag because on mine mine it will be showing without the quote like this:

<programme channel=ABC FAMILY></programme> 

here is the code:

$xml .= '<programme channel=' .$channel. '>';
Link to post
Share on other sites

The single quotes are not showing because you are using it as the string delimiter. If you want to print a literal single quote you'll need to escape it

$xml .= '<programme channel=\'' .$channel. '\'>';

//OR

$xml .= "<programme channel='" .$channel. "'>";
Link to post
Share on other sites

The code I posted is syntactically correct. You sure you tested it correctly? The \'  will print a single quote

echo 'One \'two\' three'; // outputs: one 'two' three

echo "One 'two' three"; // outputs: one 'two' three
Link to post
Share on other sites

it still don't work for me, please see it here: http://67.23.248.61/~ytestbox/test_xml.php

 

here is the update code:

 

<?php
$my_id = '101';
$channel = 'ABC FAMILY';
$starttime = '2014-05-04';
$stoptime = '2014-05-05';


$xml .= '<programme channel=\'' .$channel. '\'>';


//$xml .= "<programme channel='".$channel."' start='".$starttime."'>";
//$xml .= "<programme channel='$my_id $channel' start='$starttime' stop='$stoptime'>";


$xml .= '</programme>';


header("Content-Type: text/xml");
echo $xml;
$handle = fopen("myChannel.xml", "w"); 
fwrite ($handle, $xml);
?>
Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.