I have a text in my database with html tags to make the direction from right to left. and I am looking for a way to get the text from the database without the html tags.
this is how my text looks in the database:
<span dir="rtl"> ما هي تقنية GPS؟</span >
and I want to get it just like this:
ما هي تقنية GPS؟
I am using this code to get the text:
<?php echo $text_db; ?>
There are several ways to get rid of HTML structure from a string, the quickest you can use is strip_tags($string) - https://php.net/strip_tags
Related
I am saving data into mysql using htmlspecialchars(). On output when getting data using htmlspecialchars_decode() before displaying it in Angular. But instead of interpreting the html code it is displaying it as a text.
Data in Database
<p class="fr-tag"><span>test</span></p>
Code being displayed after htmlspecialchars_decode()
<p class="fr-tag"><span>test</span></p>
Displaying the output from database into div as follows
<div *ngIf="product.pdescription" class="mt-2 product-description">{{product.pdescription}}</div>
I have also tried using html_entity_decode but didn't help.
Following is a screenshot of the browser
In order to make it working you should use innerHTML or outerHTML binding:
<div *ngIf="product.pdescription" ... [innerHTML]="product.pdescription"></div>
But beware about some limitations
I extracted some text from an Excel file and stored it in a DB. After that, I fetch this text from the DB and display it on a page.
Below is how the problem looks like on the page:
And this is a screenshot of how it appears in the source code:
How can I format this paragraph to show in page correctly ?
Just try this
<div name="description" ....>
<pre>
.....
here your content
.....
</pre>
</div>
if not work let me know
Take a look at HTML Purifier. Pretty good at cleaning up dirty input.
http://htmlpurifier.org/
I have this textarea called personalInfos where i fill the infos in following format :
<p><span class="white">1966 - '69</span><br/> text .... </p>
When i submit it to database, it gets saved ok, same format. When i retrieve the code from database to admin textarea it gets filled ok.
My only problem is on front end where i get displayed the code as text not rendered as html code. So basiclly i see it on the page like this :
<p><span class="white">1966 - '69</span><br/>
Most likely you display fetched code parsed processed by htmlentities() or similar function. This is in most cases the way to go to avoid planting i.e. html in comments. So simply stop doing this after fetching (or insert - depends where you do so) and your content will be outputed as literaly HTML and properly processed by web browser.
You should have a look at htmlspecialchars_decode()
Example
$str = '<p><span class="white">1966 - \'69</span><br/> text .... </p>';
echo htmlspecialchars_decode($str);
Also make sure to escape the single quotes as well.
I'm relatively new to this and am familiar with echo in PHP but what I need is to have the contents of a field in a database to be placed in the page (but not as a written field)
For example
<?php echo $product_description['description']; ?>
the field description has html formating in it already so when I use 'echo' it writes out for example
<p>text on firstline <br> text on next line
And what I want is that this html from this field in the database that already has html formating to simply placed in the php page which would make it look like this
text on firstline text on next line
I assume I just need to use a different command than ECHO but don't know which one.
Try
echo html_entity_decode($product_description["description"]);
If that works, the HTML in your database has been encoded using htmlentities, so you must decode it to write to a page.
strip_tags is what you're after.
Use it like so: echo strip_tags($your database bit to echo here);
PHP docs for strip_tags
One of the fields in our PHP page is a description - occasionally there are website links included. However, when pulling this data from the database table the links remain non-clickable. How can I parse text from database table as HTML in final rendered PHP page? Thanks!
Do you mean something like this?
<?php
echo "<a href='$linkLocation'>$linkName</a>";
?>
[Edit]
Server-side you could transform the orginal text ($det[9]) like this (based on this SO question):
<div id="text"><?php
echo preg_replace_callback(
'/http:\/\/([,\%\w.\-_\/\?\=\+\&\~\#\$]+)/',
create_function(
'$matches',
'return \'\'. $matches[1] .\'\';'
),
$det[9]
);
?></div>
[Edit: merged the original code from your comment]
[Edit: fixed typo]
Are your text stored as HTML or is it just a text containing URLs?
Follow these steps
Change the db feild to text,
While inserting data convert the html entities and escape the quotes.
while retrieving do the reverse process and you can retrieve data in html format this way