Hi David, I need your help :-)
In my xml file, there's a text with this code "\n-" to make a back-on-the-line!
But when I want to display this, it is not recognized.. for ex:
in my file.xml -->
...great deal of their screens.\n\n- Highly innovative LCD monitor with S-IPS TFT display.\n- Ultra-thin frame...
in a right display-->
...great deal of their screens.
-Highly innovative LCD monitor with S-IPS TFT display.
-Ultra-thin frame...
But it's display this in my result.php -->
...great deal of their screens.\n\n- Highly innovative LCD monitor with S-IPS TFT display.\n- Ultra-thin frame...
Have yoy an idea??
Thanks
Sabri
Hi David,
your code work very fine with every kind of caracter, but the string replace doens't accept "\n" (I mean nothing happens).
I think the problem comes from "\" because when I string only "\" an error displays :
Parse error: syntax error, unexpected '>' in C:\wamp\www\cmserv\xml.php on line 8
Here's my code:
<?php
header("Content-Type: text/html;charset=utf-8");
require("MagicParser.php");
function myProductRecordHandler($record)
{
$record["PRODUCT/PRODUCTDESCRIPTION-LONGDESC"] = str_replace("\","<br>",$record["PRODUCT/PRODUCTDESCRIPTION-LONGDESC"]);
print '<link href="xmldata/css/ice.css" rel="stylesheet" type="text/css">';
print "<div class='icedesc'> ";
print "<p>".$record["PRODUCT/PRODUCTDESCRIPTION-LONGDESC"]."</p>";
print "</div>";
}
?>
Hello Sabri,
Sorry, when \ is used in a string it requires an extra \ to escape it, otherwise PHP thinks it is a litteral newline rather than the actual characters \n.
Try this version:
$record["PRODUCT/PRODUCTDESCRIPTION-LONGDESC"] = str_replace("\\n","<br>",$record["PRODUCT/PRODUCTDESCRIPTION-LONGDESC"]);
Cheers,
David.
Hello Sabri,
This looks like they have hard code "C" style new lines into their text. What I would do in this situation is pass your string through a search and replace as follows:
$example = str_replace("\n","<br>",$example);
That should turn the \n's into the HTML <BR> and it should then be displayed correctly!
Cheers,
David.