Jump to content

special chars problem


hushtalk

Recommended Posts

hi all i am new here, i was looking for some help as im stuck with something

 

i have given myself the task to make a blog script all is going fine untill this:

 

i go to mysql to fill in the form from there  i put this text:

Facebook… A phenomenon, a revelation, a lifestyle, the eighth wonder of the world… I can just go on and might probably even run out of synonyms that will do justice to this 21st Century

 

 

this is what i get when i print it

Facebook� A phenomenon, a revelation, a

lifestyle, the eighth wonder of the world� I can

just go on and might probably even run out of synonyms that will

do justice to this 21st Century marvel. There are very few sites

or companies that can boast the success Facebook

enjoys� let�s see, Google, Microsoft,

Amazon�? Hmmm, can�t think of too many

sites that can compete with Facebook when it comes to

popularity. Hell, it�s almost become a religion now

(& Iâ��m a follower I confess  ). In the 5 years it

has existed Facebook has changed the way people live.

I�m afraid we live our lives through Facebook, for

Facebook & with Facebook! It�s become so bad that I

don�t think I can even remember the time when Facebook

was not there!

All said & done Facebook is equal to oxygen for millions

& millions of people (including me!) but do we know the

journey it has gone through?

 

 

i use this to print it out

 $con = wordwrap($blogrow['content'], 64);


  
  echo $con; 

 

$con is the content

 

when i use a form to print the same its even worse,.. then it actually puts even weirder input in the database

 

any help on this please i think i almost looked all over google but what i found i can hardly understand lol

 

 

 

 

 

Link to comment
Share on other sites

hmm.. maybe i will have to play around with both

 

now i got it workin, now i figured that when i want something in bold for example i will have to add tags, like <b></b> for example,.. now with entity decode that wont work anymore ofcourse :(

 

so in  the submit entry form i suppose i will have to use htmlentuty first?

then decode again for print?

Link to comment
Share on other sites

i hope you dont mind getting deeper into this

 

the data gets entered via a simple form then insertted with this code :

foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}


mysql_query("INSERT INTO blog(title, content, date, source, source_link,picture) VALUES('$data[title]','$data[content]','$data[date]','$data[source]','$data[source_link]','$data[picture]')") or die(mysql_error());

 

 

 

then the output is like this


$thatblog = $_GET['blogid'];
if($thatblog==""){ 

 $position=50; // Define how many character you want to display.


$post = substr($blogrow['content'], 0, $position); 
$txt=html_entity_decode($post);
echo $txt;
echo "..."; ?><br/><br/><br/>
      <strong><a href="blog.php?blogid=<? echo $blogrow['id'] ?>&article=<? echo $blogrow['title'] ?>" style="text-decoration:none;color:#090"><em><br/>
      go to post</em></a></strong>
<?


 }else{

 $con = wordwrap($blogrow['content'], 64);
  
//$html = htmlspecialchars($utf8_string, ENT_COMPAT, 'UTF-8');
$txt=html_entity_decode($con);

  
  echo $txt; }

 

Link to comment
Share on other sites

Ok back to the issue... You use html_entity_decode() to translate special chars back to their characters, and with this they lose their special meaning in HTML like <b>Indeed</b>

 

In this case, prevent that the script will put the data into the DB with already html entities. Just like you would write something down, it has to go in the DB.

 

From there you must translate.

 

 

Link to comment
Share on other sites

all done and sorted and most of all working,.. i can now add tags to posts and with no weird signs showing

 

this is actually the first time on a forum like this that people take time to explain to make me understand so its easy for me to figure it out myself :)

usually or they ignore my posts or they just give me the code!

Link to comment
Share on other sites

yes i changed it to this

$postedcontent=$_POST["content"];
$postedtxt = htmlspecialchars_decode($postedcontent, ENT_QUOTES);

mysql_query("INSERT INTO blog(title, content, date, source, source_link,picture) VALUES('$data[title]','$postedtxt','$data[date]','$data[source]','$data[source_link]','$data[picture]')") or die(mysql_error());

 

 

and

if($thatblog==""){ 

 $position=50; // Define how many character you want to display.


$post = substr($blogrow['content'], 0, $position); 

echo $post;
echo "..."; ?><br/><br/><br/>
      <strong><a href="blog.php?blogid=<? echo $blogrow['id'] ?>&article=<? echo $blogrow['title'] ?>" style="text-decoration:none;color:#090"><em><br/>
      go to post</em></a></strong>
<?


 }else{
 $con = wordwrap($blogrow['content'], 64);
   
  echo $con; }

the result is i can now use tags , even embed etc

 

:)

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.