Log in

View Full Version : formatTextPar



lindsaycb
02-02-2010, 04:01 PM
I have some code that the Web Developer put in place before I was here. but I haven't been able to figure out what this one code is. It's formatTextPar. I've googled it but nothing comes up.

Here's the code: $relBody = formatTextPar($_POST['relBody']);

So I'm assuming that it formats the text differently. I'm having problems right now with the dashes not formatting correctly. I don't know how to fix that problem.

Schmoopy
02-02-2010, 04:14 PM
That'll be a custom function that the developer created. Try looking for it in one of the included files, if there are any - such as "functions.inc.php" or something similar.

Without being able to see what's going on inside the function I can't tell what's causing the problem.

lindsaycb
02-02-2010, 04:31 PM
YES! I found it! Thank you!! So here's the code associatd in the file. So from what I can gather, it looks like the formatTextChars code is in the formatTextPar but yet, it's not working any longer. Just for the Option + - dash anyway. Everything else looks to be fine.


<?php
function formatTextPar($inputString) {
$inputString = "<p>" . str_replace("</p><p></p><p>","</p><p>",str_replace("\r\n","</p><p>",$inputString)) . "</p>";
$inputString = formatTextChars($inputString);
return $inputString;
}
function formatTextLst($inputString) {
$inputString = "<ul><li>" . str_replace("\r\n","</li><li>",$inputString) . "</li></ul>";
$inputString = formatTextChars($inputString);
return $inputString;
}
function formatTextChars($inputString) {
$inputString = str_replace("&","&amp;",$inputString);
$inputString = str_replace("--","&mdash;",$inputString);
$inputString = str_replace("“","&quot;",$inputString);
$inputString = str_replace("”","&quot;",$inputString);
$inputString = str_replace("—","&mdash;",$inputString);
$inputString = str_replace("–","-",$inputString);
$inputString = str_replace("’","&apos;",$inputString);
$inputString = trim($inputString);
return $inputString;
}
?>

gurmeet
02-02-2010, 05:23 PM
use it

Schmoopy
02-02-2010, 05:25 PM
Ok, what are you passing into the function?

What does $_POST['relBody'] contain?

lindsaycb
02-02-2010, 05:31 PM
It just contains text that usually someone copies from Microsoft Word into the form. I messed with the code and it only doesn't work when it's using the Option - dash. You know how when you write 9 - 5 and then Word changes the dash into the longer dash? That's the one I'm talking about. A regular dash works fine.

Since I can't figure out why it's not working (it actually turns the longer dash into this funky image http://www.kishwaukeecollege.edu/press_releases/prArticle.php?id=577) I'll have to tell the person to always make sure that the dashes are regular sized. But I know she won't like that one bit. So if you have a solution, I'll try anything!