View Full Version : Code Fixer
Rockonmetal
09-07-2007, 11:31 PM
Ok I know javascript is a lot better at this but at the moment my Browsers are being mean to mean and not letting me view JAVASCRIPT... so I gotta use PHP...
So heres the deal:
I don't know how todo this because PHP is a little literal. I know this doesn't work but heres what I came up with...
Codefixer.php:
<form action="fix.php" method="post">
<textarea cols="50" rows="10" name="Codefixer"></textarea>
<input type="submit">
</form>
Fix.php
<?php
$Codefixer = $_POST["CODEFIXER"];
$Br = "<br>";
$Correct = "<br />";
if($Br==$Codefixer) {
echo "$Correct";
}
else
{
echo "Code Clear!";
}
?>
I was hoping so that only the <br> tags get affected, but that doesn't it just checks to see if the value is br... which isn't what I want...
Thanks for the help!
<?php
echo str_replace('<br>', '<br />', $_POST['CODEFIXER']);
?>However, I very much doubt whether converting code to IE-unsupported XHTML is "fixing" it. I'd consider it more "breaking." You should probably go the other way:
<?php
echo str_replace('/>', '>', $_POST['CODEFIXER'];
?>
Rockonmetal
09-08-2007, 01:31 AM
one small problem... how do you get it so that it goes back into a textarea...
<textarea rows="10" cols="30">
<?php echo htmlspecialchars(preg_replace('/\s*\/>/', '>', $_POST['CODEFIXER'])); ?>
</textarea>
Rockonmetal
09-08-2007, 01:40 AM
I just wanna do
<br> tags to <br /> tags sorry because i have many links on the page and lists and stuff that wouldn't work with that code... sorry
I just wanna do
<br> tags to <br /> tagsWhy? That's breaking code (unless you've dropped support for IE and are serving this all as XHTML, which I doubt).
because i have many links on the page and lists and stuff that wouldn't work with that codeWhy wouldn't they work with it? The combination /> won't appear anywhere in HTML, Javascript, or CSS; there's no reason it should break anything.
Rockonmetal
09-08-2007, 02:02 AM
k i don't think this works in html...
<a href="link.html" />CLICK HERE!</a>
You're right, it doesn't. However, the code I provided won't result in this code: it goes the other way, converting XHTML <br /> to HTML <br>, which IE can handle.
Rockonmetal
09-08-2007, 02:37 AM
k
thanks even though I can't do it by what you say above its nice to know that instead of posting 340million times and then finding out... or worse... lol thanks!
I can't do it by what you say aboveWhy? I don't think you quite understood me. Why do you think you can't use it?
Rockonmetal
09-08-2007, 03:17 AM
oh, my bad. lol, i read didn't sorry it will work, gosh what am I thinking its all this last minute work for my website...
elwinh
09-09-2007, 03:04 PM
I would do it this way if i had to write that:
<?php
function fixcode($Codefixer){
$Codefixer = ereg_replace('<br>', '<br />', $Codefixer);
return $Codefixer;
}
?>
<form action="fix.php" method="post">
<textarea cols="50" rows="10" name="Codefixer"><?php echo htmlspecialchars(fixcode($_POST["CODEFIXER"])); ?></textarea>
<input type="submit">
</form>
function fixcode($Codefixer){
$Codefixer = ereg_replace('<br>', '<br />', $Codefixer);
return $Codefixer;
}But that's essentially one statement. It's really rather pointless having one-statement functions, except for the occasional semantic benefit or where it's likely that the implementation will be changed at a later date, neither of which apply here. Also, using regex-parsing functions for static strings is a great way to waste resources, and we've already determined that it's better to use HTML than XHTML here, so the transformation needs to go the other way.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.