Click to See Complete Forum and Search --> : Converting HTML text to 1337 with PHP
Sunny G
08-22-2005, 09:41 PM
Hi everybody! I'd just like you all to know that I know absolutely no PHP whatsoever so bear with me if I don't make any sense:o
I am working on a new website (plain HTML:rolleyes:) and thought it would be fun if I could convert the text to leet using an external PHP file. Is that possible?:confused:
I want to try this because this new site is for my robotics team and the name of our first robot was "leet bot":D so I thought I'd honor it by a leet option in our website.
(Our site already has PHP enabled just FYI)
Thanks!
rch10007
08-22-2005, 10:12 PM
a simple preg_replace() function should work for you.
Read: http://www.php.net/manual/en/function.preg-replace.php
Look at example 1 as it shows how to transform an HTML doc into something else such as 133t5p33k
Sunny G
08-22-2005, 10:36 PM
OK, I don't understand that...
Genixdeae
08-23-2005, 12:20 AM
preg_replace() isn't necasary....doing str_ireplace() will work fine(it checks for lower and upper case)
http://us3.php.net/manual/en/function.str-ireplace.php
if you don't have php5 u'll have to do str_replace() for both upper and lower(as str_ireplace() is php5 only)
http://us3.php.net/manual/en/function.str-replace.php
here's an example:$string = "The letter is E";
//Not sure if this if statement will work, but it gives you the idea
if(phpversion() => "5.0") {
str_ireplace("e", "3", $string);
}else{
str_replace("e", "3", $string);
str_replace("E", "3", $string);
}
echo $string;
//output Th3 l3tt3r is 3
Sunny G
08-23-2005, 09:52 AM
K3w3l Genixdeae!
I just have a few questions about your technique...
-Will this program change ALL the pages to 1337 when they are viewed?
-How will I link to this in the HTML?
-Will this require anything else in the HTML or will the program take care of it all?
-If I upload the completed file to our existing website (http://www.team847.com/) will it work?
7h@nk5! (Thanks)
Sunny G
08-23-2005, 10:05 AM
Oh, by the way rch10007 I haven't stepped on that crown of thorns yet...
Why'd you get rid of the Brain? (Your avatar)
The're Pinky--Pinky and the Brain, Brain, Brain, Brain, Brain.....
rch10007
08-23-2005, 10:14 AM
I haven't stepped on that crown of thorns yet...
I was just kidding about that - I hope you never experience what that feels like, trust me it hurts ALOT! I got poked in the finger, I mean a tiny little poke that barely broke the skin and my finger was swollen big time and hurt like #311!!!
I like changes things up a bit with pinky. Before him I used the a pic of a bone spirit for a necromancer from Diablo 2.
Sunny G
08-23-2005, 10:18 AM
Actually before my sunny avatar and my MS paint one I used Wacko of the warner brothers! (also on animaniacs).
Genixdeae
08-23-2005, 12:54 PM
if you want to replace all the text in a html document you'll have to use preg_replace() to filter out the text that's in <> tags so html code isn't messed with, then after that's been filtered you will then take the filtered text and run it through str_replace() or str_ireplace()....I dont know enough about preg_replace() to tell you how to do this but NogDog should, so hopefuly next time he's on he'll check this
Example of final code:$file = "file/to/decode";
//Next you need to open the file and get all it's contents and store it to a variable
$file_text = fopen($file);
//Now use preg_replace to get out of the <>
$file_text = preg_replace("arguments", "replace with what", $file_text);
//Now you can go through each letter of the alphabet as i showed you above
if(phpversion() => "5.0") {
str_ireplace("e", "3", $file_text);
}else{
str_replace("e", "3", $file_text);
str_replace("E", "3", $file_text);
}
echo $file_text;The code above wont work, but it gives you the idea of the final output, you could event make it to a function(which might be better todo)
Sunny G
08-23-2005, 04:16 PM
OK. I'll PM or Email NogDog and see if he'll help.
Thanks!
You can make it even simpler by using output buffering.
Example:
<?php ob_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Some Odd Document</title>
</head>
<body>
<h1>abc</h1>
<p>testing</p>
</body>
</html>
<?php
$contents = ob_get_contents();
ob_end_clean();
function txt2leet($input) {
$replace = array( // set this up here for what becomes what
'a' => 1, // a becomes 1
'b' => 2, // b becomes 2
'c' => 3, // etc etc
'd' => 4,
'e' => 5,
'f' => 6,
'g' => 7
);
$output = $input[1];
foreach ($replace as $from => $to) {
$output = str_ireplace($from,$to,$output);
}
return '>'.$output.'<';
}
$contents = preg_replace_callback('/>(.+)</','txt2leet',$contents);
print $contents;
?>
Sunny G
08-24-2005, 09:28 AM
K3w31 Mau!
Does that work? How would I go about activating the PHP part of the page, or is it automatic and converts to 1337 on load?
Thanks!
Yes, that is a full working example. Just place the ob_start() at the start of every page, and the text at the bottom at the very end. :)
It converts the page to leet on the fly (anything that isn't inside < and >). Beware, that it will convert JavaScript directly embedded:
<script>
<head>
function foo { // this will become leet!!
return bar;
}
</script>
</head>
So, you should reference to outside files instead:
<script src="blah.js"></script>
Sunny G
08-24-2005, 07:14 PM
Is there any way I can make it so it will convert apon the user's demand and not apon load?
theuedimaster
08-24-2005, 08:57 PM
yea have it as a submit button to the page itself with a value and then put an if funciton to include the file if that value is seen.
Genixdeae
08-24-2005, 09:06 PM
you could just set a session or add a variable to the url
EG:: page.php?leetit=1
then on your page put a if->then statment...
if(!empty($_GET["leetit"]) && $_GET["leetit"] == "1") {
run leeting script
} //otherwise do nothing
Sunny G
08-25-2005, 10:08 AM
OK, I'm really confused... I don't know PHP and all you guys are saying is making my head spin in a whirlwind of confusion.
Sunny G
08-26-2005, 01:56 PM
or add a variable to the url
Wait.... A variable? What's that?
Genixdeae
08-26-2005, 03:33 PM
leetit is the variable in the example above your url would now looksomething like this:
page.php?leetit=1 //Do this to leet it
page.php //Do this to do nothing
Sunny G
08-27-2005, 02:31 PM
OK, I'll give that a try...
Thanks for sticking with me guys!