Forum Moderators: coopster

Message Too Old, No Replies

PHP/MySQL: String problem

PHP/MySQL: String problem

         

bikoy83

2:55 am on Aug 13, 2005 (gmt 0)

10+ Year Member



Hello,

I have tried to retrieve a value of the database and used it on the Meta Description of my site. My problem here is that the string appears to break lines.

Example:
-----------------------------------------
<meta description="the quick brown

fox jumped

over the lazy dog">
-----------------------------------------

And I want it to appear this way:

<meta description="the quick brown fox jumped over the lazy dog">

Is there a function that can solve this?

Thanks and hope to hear from someone soon! :-)

bikoy83

2:58 am on Aug 13, 2005 (gmt 0)

10+ Year Member



sorry for the typos, that would be:

Example:
-----------------------------------------
<meta name="description" content="the quick brown

fox jumped

over the lazy dog">
-----------------------------------------

And I want it to appear this way:

<meta name="description" content="the quick brown fox jumped over the lazy dog">

roldar

1:35 am on Aug 14, 2005 (gmt 0)

10+ Year Member



You might give the following a try:

/*From the database you get your meta description text*/
$metatext=$thisrecord['meta_description'];

$metatext=htmlspecialchars(str_replace("\n", "", str_replace("\r", "", $metatext)));

/*The htmlspecialchars is primarily there to change quotes to char entities so they won't prematurely close the meta tag. The two str_replace() functions get rid of the returns/newlines*/

<meta name="description" content="<?php echo $metatext;?>">

bikoy83

4:27 am on Aug 14, 2005 (gmt 0)

10+ Year Member



thanks a lot! just what i needed! :-)