AllExperts > PHP5 
Search      
PHP5
Volunteer
Answers to thousands of questions
 Home · More PHP5 Questions · Answer Library  · Encyclopedia ·
More PHP5 Answers
Question Library

Ask a question about PHP5
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Kevin Cackler
Expertise
Any and everything related to PHP4 and PHP5. I specialize in functional, readable, scalable object oriented code, and can answer your troublesome class and object questions.

Experience
5 years developing in PHP using flat files and databases (MySQL, Oracle) Lead PHP developer for a very large Texas based web hosting company The coder behind some of the largest pet communities online.

Education/Credentials
BS - IT/CS

 
   

You are here:  Experts > Computing/Technology > Perl/PHP > PHP5 > Output apostrophes, quotation arks etc from Mysql database

PHP5 - Output apostrophes, quotation arks etc from Mysql database


Expert: Kevin Cackler - 10/14/2009

Question
I need to display mysql data with php 4 or 5 that has apostrophes etc. within the text. The data is read directly from the database and displayed within strings using echo and printf statements.

I have included a code example below;

printf("<td><p><img src=\"$ABSOLUTE_PATH_1%s\" align=\"center\"</p><p class='heading2'>%s</p><p>%.20s<br><a href=\"%s?id=%s\">  (MORE)</a><br></p></td>", $row["image_1"], $row["project"], $row["company"],$PHP_SELF, $row["id"]);

echo ("<img src='$ABSOLUTE_PATH_1$row[2]' hspace=\"5\" vspace=\"5\" align='left' border =\"1\"><h2>$row[4]</h2>$row[5]");

How do I do this?

Many thanks

Answer
I apologize, but it's very difficult to understand what you're trying to do, still.  

However, if I've understood your question properly, what you want is concatenation.  Your line can be changed to look like this:



echo '<img src="' . $ABSOLUTE_PATH_1 . $row[2] . '" hspace="5" vspace="5" align="left" border ="1"><h2>' . $row[4] . '</h2>' . $row[5];

In case you aren't able to tell, concatenation involves stopping the parsing of your text (IE, if you started with echo ', then to stop termination you place a '), then add a . then add your variable then add a . and then start up the parsing again with your opening quote '

A simpler example

<?php
$var='Kevin';

echo $var . ' Cackler';
echo 'Cackler, ' . $var;

?>


Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.