Click to See Complete Forum and Search --> : Str_replace # with a new paragraph


daniish
02-15-2008, 05:48 AM
Hello,

I have a simple form where i would like the character '#' to represent a new paragraph (double carriage-return and a small indent). Using the following syntax how can this be coded for:

$xmlStr=str_replace('<','&lt;',$htmlStr);


Many thanks for your attention

TheRave
02-15-2008, 05:55 AM
w3schools.com has information on most of the common php functions. Check out how to use str_replace here:
http://www.w3schools.com/php/func_string_str_replace.asp

The first parameter is the thing you're trying to find: #
The second paramater is the thing you're trying to replace: <br /><br />
(I assume you want it to be a html crlf.)
The third paramter is the thing to be searched: (This depends on your previous code.)
The fourth parmater is optional: (You don't need it.)

Now have a go yourself at putting it together.

daniish
02-15-2008, 06:50 AM
At the moment i have the following:

$xmlStr=str_replace("#",'&<br /><br />;',$htmlStr);

but it doesn't work! Have i got the structure of it wrong?

TheRave
02-15-2008, 07:21 AM
$xmlStr=str_replace("#","<br /><br />",$htmlStr);

daniish
02-15-2008, 08:19 AM
Unfortunately that doesn't work.

On my site google markers are displayed from a mysql db - but at the moment this only occurs if that line above is not present, so there must be some issue with it!

http://www.globexposure.net/index_basic_v2.php

TheRave
02-15-2008, 08:43 AM
Sorry its not working. You've only given me one line of code to work on, I have no idea of the context.

Its like sending your car to a mechanic to fix the steering but not letting him see the car, only letting him see the wheel and without letting him know what kind of car it is and even what kind of steering it is. The mechanic would probably not be able to fix the problem.

So, please, if possible, post more/all of your code.

If in doubt post all your code. It will help me/anyone help you.

daniish
02-15-2008, 09:02 AM
Sorry about that...

$query = "SELECT id, name, title, date, description, lat, lng FROM locations WHERE 1";
$query = mysql_query($query);

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&apos;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
$xmlStr=str_replace("#","<br /><br />",$htmlStr);
return $xmlStr;
}

echo "<locations>";
while ($row=mysql_fetch_assoc($query)){
echo '<location id="'.$row['id'].'" title="'.parseToXML($row['title']).'" date="'.$row['date'].'" name="'.parseToXML($row['name']).'" description="'.parseToXML($row['description']).'" lat="'.$row['lat'].'" lng="'.$row['lng'].'"/>';
}
echo "</locations>";

is that sufficient?

TheRave
02-15-2008, 09:10 AM
$xmlStr=str_replace("#","\n",$xmlStr);

daniish
02-15-2008, 09:26 AM
The markers display now but this is still not creating new lines in the text as it should.

Do you have any other ideas?

NogDog
02-15-2008, 10:18 AM
function parseToXML($htmlStr)
{
return(htmlspecialchars(str_replace("#","<br /><br />",$htmlStr), ENT_QUOTES));
}

daniish
02-15-2008, 11:54 AM
That's it NogDog thank you so much!

Special thanks to TheRave also for his efforts.