I wrote the code for a php based bb code parser function. I hope you all like it. I commented on every single line of code. I will explain how to parse
I will explain how to use this with a function to parse data and write it to a file, or to get data from a database, parser it, then write it file in part 2 which I will be working on soon. This is good to limit what html people can use.
I will write a new tutorial when my donatometer reaches 100, send me a transfer of any amound of frih$ and each frih$ give me 1 donatometer point.
Donatometer
Everytime I recieve a donation with a pm attached saying "donatometer, I record one more point, every 5 points you get an extra - deleted, I will expand the chart every 25 points. The more you donate the more chances you have towards me releasing a new tutorial. I gave 5 points free.
Thanks to:
Mathius - 10 frih$
N00Bie4Life turned this into a sticky, I gave some extra points for that.
|||0
|||5
|||10
|||15
|||20
|||25
|-|30
|-|35
|-|40
|-|45
|-|50
|-|55
|-|60
|-|65
|-|70
|-|75
|-|80
|-|85
|-|90
|-|95
|-|100
Last edited by mattd8752 on Wed Dec 21, 2005 10:53 pm; edited 5 times in total
| Code: |
| <?php //Defines the start of a block of php code.
//Anything with // infront of it is a comment and is only readable when editing. //BBCode Parser //Create the function. //Function tells php that this is creating a function. //BB follows to tell php that bb is the name of the function. //Text is what would go in the brackets of the command. function bb($text) { //This establishes the start of the function commmand. $array=array( //This creates an array with the name $array. "[b]" => "<b>", //This sets the value of [b] to <b> so if you looked under [b] in the array you would find <b>. "[/b]" => "</b>", //This sets the value of [/b] to </b> "[i]" => "<i>", //This sets the value of [i] to <i> "[/i]" => "</i>", //This sets the value of [/i] to </i> "[u]" => "<u>", //This sets the value of [u] to <u> "[/u]" => "</u>", //This sets the value of [/u] to </u> "[center]" => "<center>", //This sets the value of [center] to <center> "[/center]" => "</center>", //This sets the value of [/center] to </center> "[big]" => "<h1>", //This sets the value of [big] to <h1> "[/big]" => "</h1>", //This sets the value of [/big] to </h1> "[nl]" => "<br>", //This sets the value of [nl] to <br> ); //This is the end of the data. $newtext = str_replace(array_keys($array), array_values($array), $text); //This takes the name of the components like //[b] and the others which I showed to their value. It puts $newtext as a varuible to run this. return $newtext; //$newtext is sent back to the function requesting php. It also runs the str_replace which was set to //this varuible. } //The function is now ended. ?> //Defines the end of a block of php code. |
I will explain how to use this with a function to parse data and write it to a file, or to get data from a database, parser it, then write it file in part 2 which I will be working on soon. This is good to limit what html people can use.
I will write a new tutorial when my donatometer reaches 100, send me a transfer of any amound of frih$ and each frih$ give me 1 donatometer point.
Donatometer
Everytime I recieve a donation with a pm attached saying "donatometer, I record one more point, every 5 points you get an extra - deleted, I will expand the chart every 25 points. The more you donate the more chances you have towards me releasing a new tutorial. I gave 5 points free.
Thanks to:
Mathius - 10 frih$
N00Bie4Life turned this into a sticky, I gave some extra points for that.
|||0
|||5
|||10
|||15
|||20
|||25
|-|30
|-|35
|-|40
|-|45
|-|50
|-|55
|-|60
|-|65
|-|70
|-|75
|-|80
|-|85
|-|90
|-|95
|-|100
Last edited by mattd8752 on Wed Dec 21, 2005 10:53 pm; edited 5 times in total
