Click here to Skip to main content
14,736,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am trying to set the description of my page from a retrieved description from a PHP call using this code:

<description><?php echo $description; ?></description>

but sometimes the description has special characters, for example:

this is a description of "technology!" website



this is cause a problem when I open the website because it will just echo the description on the page itself

How can I fix this please?


Thanks,
Jassim

What I have tried:

<description><?php echo $description; ?></description>
Posted
Updated 18-Feb-20 0:59am

1 solution

PHP has a function just for this
PHP Manual
htmlentities: 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.
Reference:
PHP: htmlentities - Manual[^]
   
Comments
Jassim Rahma 18-Feb-20 6:58am
   
But I am still having the problem even with using htmlentities.

Here is the test link and you can see two problems:

1. there is an output test shown on the top.
2. The format is not exactly as per the original page.

The Link:

https://www.softnames.com/tempopengraph/index2.php

The Original Page:

https://www.bbc.com/arabic/world-51522045
MadMyche 18-Feb-20 7:03am
   
The page you are creating is not valid HTML; You can see your HEAD section being written out and then you grab the copy from BBC which has another HEAD section. There is also no AUTHOR or DESCRIPTION elements in the HEAD element.
Jassim Rahma 18-Feb-20 11:53am
   
Then what's the best way if I want to use my own page (own head and meta tags) with just embedding other pages? my main purpose is to provide a header with a back button or my page logo

How can I do that without having to use frames?
MadMyche 18-Feb-20 12:37pm
   
The correct way would be to only take the "body" portion of the retrieved page.

And... seeing what you are doing; do you have permission from the BBC to re-use their content?
Jassim Rahma 18-Feb-20 13:02pm
   
But if I take the then all links within the head won't be included, e.g. CSS or scripts?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900