Reputation: 3
"contentDetails" has following data in it:
<p>This is data sample. </p><p>Second part of the paragraph. </p>
str_replace is not working here. Please take a look.
here is how my xml strucuture in php looks like:
$xml = <?xml version="1.0" encoding="UTF-8">;
$xml = '<root>';
$xml = '<myData>';
$xml .= <content> . str_replace(" ", "", htmlentities($_POST[contentDetails])) . </content>
$xml = '</myData>';
$xml = '</root>';
Upvotes: 0
Views: 850
Reputation: 47
The htmlentities() function converts to &nbsp; --- so try this...
str_replace("&nbsp;", "", htmlentities($_POST[contentDetails]))
Upvotes: 1
Reputation: 147146
I'm assuming your contentDetails
actually contains:
<p>This is data sample. </p><p>Second part of the paragraph. </p>
($nbsp;
replaced with
)
Your problem is that when you call htmlentities
on contentDetails
it converts
into &nbsp;
, so your str_replace
won't find any matches. To solve the problem, call str_replace
before htmlentities
:
$xml .= '<content>' . htmlentities(str_replace(" ", "", $_POST['contentDetails'])) . '</content>';
Note that associative array keys should be enclosed in quotes; this will cause a warning now but in future PHP versions will be an error.
Upvotes: 1