display data into html table which have special character - php

Deat All, How do i display data into a html table if my data have like the below:
$str=<table border='1' width='100px'><tr><td>30-00463-00P12><CARDS PENGUIN PICK “UP” HALVES &DOUBLES PK 18><VEST, “RELEASABLE” PACK, ‘MD’, WC W/ ARM</td></tr></table>
I want to display data into a table like "30-00473-03 MAGNETS GEOMAG 216 PIECES GEO76> are misssing.and it does noty print after <> ..i want diaply all character with this special character..Hope you got ..what i want ??
Please help me.

Try using the htmlentities() function in PHP as follows,
echo htmlentities($str);
it will automatically replace special characters by the corresponding HTML entities.
** For more info - htmlentities()

Related

How to get editor data without any special character in php

I am working with php and i am trying to get data from "Editor" ( like Tinymyc),But
right now i am getting special characters like "<strong> ,<p>" etc..i just want to get simple data
without any special characters,how can i do this ?I tried with following code
$data=$_POST['editor'];
Give this a try - if your code is correct this should work.
$data = strip_tags($_POST['editor']);

How can I display the HTML tag correctly

I will read an email via PHP.
However I'm stocking at the following point.
I receive the values from the mail via class id's:
$Sadress_Lname = utf8_encode(quoted_printable_decode(get_content($bodyText,'<span id=3D"Sadress_Lname">','span')));
If the received value contains an html tag which is divided by an UTF 8 sign, it doesn't work.
Example:
<p>span id=3D"Sadress_Lname">Meier</=`span></p>
This will ouptput: Meier</= span> ...
Can someone helpme to decode it, to display just "Meyer"?
Try to remove the
=`
on span tag

How to retrieve some special characters (& ,<) from sql while using AJAX

I am saving user fed text entered in a text box into the database and then retrieving the entered text using ajax(using JavaScript and not jQuery).
All special characters are getting inserted well in mysql but it is not able to retrieve the data containing special characters. Greater than (>) symbol is getting retrieved successfully but & and < is causing the whole page to load without any result.
Code for inserting data:
for($i=0;$i<$No_of_Inp_Fields; $i++)
{
$Desc = $_POST['txtdesc'.($i).''];
$inquery="INSERT INTO DETAILS VALUES ('$Desc')";
$sSql = mysql_query($inquery);
}
Code for retrieving the data
$queryPopIP=mysql_query("select Desc from DETAILS where Nm='$tag'");
$resPopIP=mysql_fetch_array($queryPopIP);
$DesPop=$resPop[0];
This is sent as a response using php
Code for displaying the data(using javascript)
var desIP=serverResponse.split('_');
document.getElementById('popdiv2').innerHTML="<b>"+desIP[1];
No jQuery... add the text as a text node. It'll preserve the angle brackets or other special characters.
document.getElementById('someElement').appendChild( document.createTextNode('<b>sushi</b>') );
I think this what you are asking? Honestly still not a 100% clear.
If that's not it, you probably need to call htmlentities on your data (if you are using PHP) when you are displaying the values of your data.
EDIT
Since it looks like $DesPop is what you send through AJAX, do this in your PHP
$DesPop = htmlentities($resPop[0]);

Show HTML special characters as is

I need to display a few item names as it is stored in database. It is working fine except when the name contains HTML special characters. For eg: if the name is like <ItemName> it is showed as <ItemName> when echo it using PHP. How can I prevent this. Also if the name is stored in DB as <ItemName> it should show like that only. When I tried to use htmlentities(), it is showing the & as & and that isn't what I need to show. How this can be fixed ?
Also I am using Highcharts and it has the item names as labels. So the name <ItemName> (if with tags), needs to be converted to htmlentities() in order to display it correctly. Otherwise, it will not show the label.
Just use htmlspecialchars function
<?php
echo(htmlspecialchars('<ItemName>something</ItemName>'));
or as in your case:
<?php
echo(htmlspecialchars('<ItemName>something</ItemName>'));

PHP/MySQL: Strange output issue when echoing variable from MySQL database

I have a MySQL table that contains names and e-mail addresses. The data was originally imported from a .csv file, and it did not originally contain complete e-mail addresses. We had to append the #place.domain to the user's alias.
When the data is sitting in the MySQL table, it looks normal: person#place.domain; however, when I output the content in PHP, I get this: person #place.domain. There's always a space between the person and the #. It doesn't look like that in the MySQL column, nor does it look like that when I copy/paste the data into Notepad, Word, Excel, etc. Furthermore, if I erase the data in the column and manually replace it with person#place.domain, it displays normally in my PHP app. So I'm guessing there's some hidden character that PHP is picking up that I can't detect. Is there a way for me to clean this up? I've tried TRIM(), REPLACE,(), etc., all to no avail.
UPDATE: I've discovered that, when I click in the MySQL field and move among the characters using my arrow keys, I have to hit the arrow key TWICE to move past the # symbol, yet there is no visible space.
I made this sample code for you:
<?php
$test = "user #mail.com";
$aux = explode("#",$test);
$mailok = trim($aux[0])."#".trim($aux[1]);
echo $test." vs ".$mailok;
?>
This is likely something like non-breaking space (ascii 160). To get rid of it:
UPDATE my_table SET e_mail = REPLACE(e_mail, CHAR(160), '');
Try with a foreach cycle, and do the chr($char) function to every character in the string, it will display you the ascii code of each character in the string, and you will find the wrong character. It's the only solution I found. Hope to be useful

Categories