caine Posted December 20, 2006 Share Posted December 20, 2006 I have data ready in my mysql db, which are extracted from xml website. Therefore, the data are originally in html entities, but I want to display them in normal characters after retrieved them from mysql. It was unsuccessful attempt with the error statement :Fatal error: Call to undefined function: htmlspecialchars_decode() in C:\Program Files\xampp\htdocs\search_results_new.php on line 90Hopefully anybody can help with this. [code]<html><head><title>Searching Results</title></head><body><?php $display ="<h1>Searching Results</h1>"; //perform searchif(isset($_POST['submit'])){ $db = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("bulletin", $db) or die(mysql_error()); $searchWords = explode(" ", $_POST['textfield']);foreach ($searchWords as $word) { if ($word) { $whereParts[] = "`TITLE` LIKE '%{$word}%' OR `DEPARTMENT` LIKE '%{$word}%'" ; }} $whereClause = implode(" OR ", $whereParts); $query = "SELECT * FROM `bul_data` WHERE {$whereClause} ORDER by DATE"; $res = mysql_query($query) or die(mysql_error()); echo "query=".$query; if(mysql_num_rows($res)>0) { echo "<table width=\"100%\" border=\"1\">"; echo "<tr>"; echo "<th>Date</th>"; echo "<th>Title</th>"; echo "<th>Department</th>"; echo "<th>Link</th>"; echo "</tr>"; while($row=mysql_fetch_assoc($res)) { $date = $row['DATE']; $date = decode($date); $title = $row['TITLE']; $title = decode($title); $department = $row['DEPARTMENT']; $department = decode($department); $campus = $row['CAMPUS']; $campus = decode($campus); $link = $row['LINK']; $link = decode($link); $display .= "<tr> <td><strong>$date</strong></td> <td><strong>$title</strong></td> <td>$department</td> <td><a href = \"$link\">$link</a></td> </tr>"; } $display .="</table>"; } echo $display; }else{ echo "No matches.";}function decode($text){ $text = htmlspecialchars_decode($text,ENT_QUOTES); return $text;} ?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 20, 2006 Share Posted December 20, 2006 what version of PHP are you using? 5? Quote Link to comment Share on other sites More sharing options...
caine Posted December 20, 2006 Author Share Posted December 20, 2006 Hi, nice to hear from you again. Yeah, I'm using php5 Quote Link to comment Share on other sites More sharing options...
Orio Posted December 20, 2006 Share Posted December 20, 2006 Are you sure you are using the version needed?Run a file that contains:[code]<?php echo phpversion(); ?>[/code]Anyway, you can always use this function that I found in "User Contributed Notes" in htmlspecialchars_decode()'s page in the manual.[code]<?phpif ( !function_exists('htmlspecialchars_decode') ){ function htmlspecialchars_decode($text) { return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS))); }}?>[/code]Orio. Quote Link to comment Share on other sites More sharing options...
caine Posted December 26, 2006 Author Share Posted December 26, 2006 It's still doesn't work either. But if I use html_entity_decode(), it works, but there's still some special characters remained, i.e. ý. Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted December 26, 2006 Share Posted December 26, 2006 I've noticed when parsing XML, that there are special characters not handled by the above mentioned php functions. So, I ended up writing some code using preg_replace to handle these special characters. I know it's not real clean, but it's easy to maintain as you find additional characters that need to be replaced in the XML feed. Something like:[code]<?php//get $input from your XML feed$xml_char = array('/</','/'/'); //add encoded characters to this array//note: the above array values should be the ampersand followed by the encoded value, but the forum seems to keep converting the ampersand to it's encoded equivalent...but, you get the picture.$html_char = array("<","'"); //add corresponding decoded characters to this array$output = preg_replace($xml_char,$html_char,$input);?>[/code] Quote Link to comment Share on other sites More sharing options...
caine Posted December 30, 2006 Author Share Posted December 30, 2006 Ok, but how do I get to know the exact number representation of the encoded characters, i.e. '/&#60;/','/&#039/'? Where to find the complete list of characters matching with the numbers? Besides, what will be the $input? Quote Link to comment Share on other sites More sharing options...
caine Posted January 24, 2007 Author Share Posted January 24, 2007 I still fail to replace ý with ! using the str_replace function. How do I tackle this? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.