How to remove and special characters like &#�?

I'm trying to develop the dynamic site using php and mysql. I need to extract limited contents from my database so I've used substr but I'm troubled with unnecessary enter so want to remove enter (br) and special characters like &#�?.

My code looks like this.

<?php $sql = "SELECT contents FROM table"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $contents = $row['contents']; echo substr($fld_page_details, 0,125); } ?>

Any suggestion is appreciated.

--------------Solutions-------------

Try to set like this to set character set mysql_set_charset("UTF8"); and header('Content-type: text/html; charset=utf-8');

<?php

$sql = "SELECT contents FROM table";
mysql_set_charset("UTF8");
$result = mysql_query($sql) or die(mysql_error());
header('Content-type: text/html; charset=utf-8');
while($row = mysql_fetch_array($result))
{
$contents = $row['contents'];
echo substr($fld_page_details, 0,125);
}

?>

If you want to remove html tags you can use strip_tags().

$htm = "<b>Hello world</b>";
$rsp = strip_tags($html);
var_dump($rsp);

More info

Category:php Time:2017-12-06 Views:3
Tags: php mysql

Related post

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.704 (s). 13 q(s)