Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Wierd characters such as €™ keep on appearing in my html strings - own blog project

Hi there - 'afternoon!

I have recently been trying my hand at building my own blog from scratch, (entirely in hand-code), using the PHP-PDO syntax. The blog works, and the posts appear on the front page, but when the user views the 'view-post' page, which displays the full text of the post, the text has not been properly converted to HTML, and the special chars haven't been escaped. There are lots of wierd characters in the text.

Any solutions in how to fix this? My code is below.

Robert

viewpost.php:

<?php

require_once('includes/config.php'); try { $results = $db->prepare(" SELECT postID, postTitle, postCont, postDate FROM blog_posts WHERE postID = :postID"); }

$results->execute(array(':postID' => $_GET['id'])); $row = $results->fetch(PDO::FETCH_ASSOC);

} catch (Exception $e) { echo "Data could not be retrieved from the database."; exit; }

if($row['postID'] == ''){ header('Location: ./'); // if there is no postID coming from the database, there is no record, so redirect the user to the index page. exit; }

echo '<div>'; echo '<h1>'.$row['postTitle'].'</h1>'; echo '<p>Post on '.date('jS M Y', strtotime($row['postDate'])).'</p>'; echo '<p>'. htmlspecialchars_decode($row['postCont']).'</p>'; echo '</div>';

?>

Output:

It's a typical problem. A client approaches you looking for a top-of-the-range website, in order to market a product. They have tonnes of ideas about the purposes of the site and its main aims – to promote the material they developed – and more often than not to increase their digital footprint – but they have no material or ideas for the visual design of the site. It’s at this point that you consider the design options available. At the most simplest and quickest level, PowerPoint – although technically not a graphic design tool – is a candidate for the job. Its simple shape tools and quick colour fill & text options mean that a visual design can be drawn up in minutes. However, it is not the best tool for quality and artistic finesse, and it may leave the client disappointed with their first impressions of your work. Adobe Photoshop is another option in the web designer’s palette. Its large number of blending options mean that gradients, bevels and high-quality finishes can be added to create just the perfect design. But perhaps do not keep too a watchful eye on the clock – it is

etc.

Really weird problem!!

Thanks,

Robert London, UK

1 Answer

On which Charset is you DB on? Is it on UTF8?