473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Reversing htmlspecialchars?

155 100+
I have this when posting to a database:
[PHP]$a = htmlspecialchars($_POST['article']);
$a = addslashes($a);[/PHP]

I have this when displaying the data on a Web page:
[PHP]$article=nl2br(stripslashes(mysql_result($result,$ i,"article")));[/PHP]
The stripslashes works, but the html characters show up, i.e. < >, etc.

htmlspecialchars going into the database is good, but how do I reverse it to display in a Web page?

Thanks.
Jul 24 '07 #1
3 2879
DavidPr
155 100+
I found this but how would I implement it?
[PHP]<?php
if ( !function_exists('htmlspecialchars_decode') )
{
function htmlspecialchars_decode($text)
{
return strtr($text, array_flip(get_html_translation_table(HTML_SPECIAL CHARS)));
}
}
?>[/PHP]

Would I replace $text with my database fields? if so would I need to repeat this code for each field?
Jul 24 '07 #2
ak1dnar
1,584 Expert 1GB
Its a function. so put it in a global file :
Expand|Select|Wrap|Line Numbers
  1. function htmlspecialchars_decode($text)
  2. {
  3. return strtr($text, array_flip(get_html_translation_table(HTML_SPECIAL CHARS)));
  4. }
  5.  
and include that file for your php scripts(that you expecting to use the function)

Now call for that function with the Parameters you want to decode.
Expand|Select|Wrap|Line Numbers
  1. $decoded_String = htmlspecialchars_decode($pass_the_string_to_decode)
  2.  
Jul 24 '07 #3
DavidPr
155 100+
Yes, I overlooked that this was a function for some reason. I have it in my functions page now, thanks.

David
Jul 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Phil Powell | last post by:
If $val is the following: ....Just revamped the site's Content Management Application I built.. so do bear in mind.. sorry! Phil stripslashes(htmlspecialchars($val)) should produce the...
3
by: SoulSniper | last post by:
I'm working on a modification to a popular blog script, the modification is for putting source code into a post for the world to see. The idea is exactly the same as putting code into a post on a...
0
by: lawrence | last post by:
Using the conversion to char sets described for these functions, is it possible to get a whole string into some charset? I'm trying to figure out a way to take invalid character sets from idiot...
1
by: leegold2 | last post by:
Newbie question I guess. Please show me how to use the htmlspecialchars function in the form below, Thanks: <form action="formtest1.php?c=1" method=POST> <b>Find Results with: These words:...
1
by: brianj | last post by:
Running php 4.3.6 on winxp machine I have following code: ----------------------------------------------------------------------- Restaurants <select size='1' name='restaurants'> <? while (...
4
by: Kevin | last post by:
Hello, I need to some help in reversing an 2-dimensional array. I am working with gif images and I am trying to make the mirror image. I was hoping that someone could help give me a headstart...
2
by: universalbitmapper | last post by:
Hi, $new = htmlspecialchars("<a href=", ENT_QUOTES, 'ISO-8859-15'); echo $new; displays: <a href Instead of :
1
by: Software Engineer | last post by:
Testing htmlspecialchars() PHP Function - Converting HTML Characters http://sqa.fyicenter.com/Online_Test_Tools/Test_htmlspecialchars_PHP_Function.php When data needs to be presented in Web...
8
by: mijn naam | last post by:
Can someone please explain to me why/when one would use htmlspecialchars instead of htmlentities? I know: if you only want to get certain characters translated. This is not the answer I'm...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.