Anders Moen Posted January 20, 2007 Author Share Posted January 20, 2007 And how do I insert it?This is how some of the rest looks:$tekst = str_replace("[*code]", "<div style='background-color: #f2f0e7;'>", $tekst);$tekst = str_replace("[/code*]", "</div>", $tekst); // without the stars of course I didn't excactly get what you meant then. So can you use the whole thing? Link to comment Share on other sites More sharing options...
MrAdam Posted January 20, 2007 Share Posted January 20, 2007 $tekst = strip_tags($tekst); Link to comment Share on other sites More sharing options...
Anders Moen Posted January 20, 2007 Author Share Posted January 20, 2007 And then I don't need anything more? It automatically makes < to < ??:)Now the <span style='font-size: 15pt;'>text</span> doesn't work when I add text Link to comment Share on other sites More sharing options...
Kristian_C Posted January 21, 2007 Share Posted January 21, 2007 Dont know if this helps or if this is what you want but : function rep2($tekst) {$tekst = str_replace('<','<',$tekst);$tekst = str_replace('>','>',$tekst);$tekst = str_replace('"','\"',$tekst);$tekst = str_replace(''',"'",$tekst);$tekst = str_replace('amp;','&',$tekst);return $tekst;} Just copyed now so just take the function content and insert into the code i gave you if you still use it, if not i cant help you. ->Kristian_C. Link to comment Share on other sites More sharing options...
Anders Moen Posted January 21, 2007 Author Share Posted January 21, 2007 Still doesn't work :/ Link to comment Share on other sites More sharing options...
MrAdam Posted January 21, 2007 Share Posted January 21, 2007 look what else you can do with strip_tags() - http://uk.php.net/strip_tags - you can set what tags are allowed. Link to comment Share on other sites More sharing options...
Anders Moen Posted January 23, 2007 Author Share Posted January 23, 2007 It didn't help me much, because I seriously don't have time to read all this stuff, although it's the only way to learn :/ Link to comment Share on other sites More sharing options...
justsomeguy Posted January 23, 2007 Share Posted January 23, 2007 You don't have time to learn? Well you know what they say, you can either take the time to do it right or make the time to do it over. Link to comment Share on other sites More sharing options...
Anders Moen Posted January 23, 2007 Author Share Posted January 23, 2007 I know, but I just don't have time enough to read all that stuff. I wish I had though =/We have way too much to homework and stuff...Oh well, I'll try to get some time so I can read it soon Link to comment Share on other sites More sharing options...
MrAdam Posted January 23, 2007 Share Posted January 23, 2007 quite simple really. Any tags you don't want removing (so anything required for bbcode) you just add to the function parameter: $tekst = strip_tags($tekst, '<p>,<span>'); Link to comment Share on other sites More sharing options...
Anders Moen Posted January 23, 2007 Author Share Posted January 23, 2007 Ah, thank you :)I'll try it later, but now I have to do homework Link to comment Share on other sites More sharing options...
Anders Moen Posted February 1, 2007 Author Share Posted February 1, 2007 I haven't made it work yet :SIt just doesn't want to work...bet it's because I'm trying to make it work and not someone else ;p Link to comment Share on other sites More sharing options...
thibo1025 Posted February 1, 2007 Share Posted February 1, 2007 I have anotther question ,I just want to make sure php dosen't switch by doing this:' -> \' and \ -> \\and I want than the text to be writen in a new file...my code to do so is this: function fix($texte) {$texte = str_replace('<','<',$texte);$texte = str_replace('>','>',$texte);$texte = str_replace('"','\"',$texte);$texte = str_replace('\'', '\\\'',$texte);$texte = str_replace('\\', '\\\\',$texte);$texte = str_replace('amp;','&',$texte);return $texte;}//etc...$fh = fopen("my_page.htm", 'w') or die("It didn't work!');fwrite($fh,"".fix($ftexte."");fclose($fh);//$texte is already set above but he content of it dosen't matter... Link to comment Share on other sites More sharing options...
justsomeguy Posted February 1, 2007 Share Posted February 1, 2007 You have a syntax error on this line:fwrite($fh,"".fix($ftexte."");it should be this:fwrite($fh, fix($ftexte));other then that, is there another problem? Link to comment Share on other sites More sharing options...
Anders Moen Posted February 1, 2007 Author Share Posted February 1, 2007 Answer my question instead :)Hehe, I'm just joking, but I really need to find out and I can't figure it out myself =/ Link to comment Share on other sites More sharing options...
thibo1025 Posted February 1, 2007 Share Posted February 1, 2007 justsomeguy > Thanks a lot I was stuck on it for days... Ican't beleive I didn't see that stupid error.andersmoen > Did you try-it like this? <?php$con = mysql_connect("localhost","username","password");if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("database", $con);function bbcode($tekst){// Alignment of a text:$tekst = str_replace("[center]", "<div align='center'>", $tekst);$tekst = str_replace("[/center]", "</div>", $tekst);$tekst = str_replace("[left]", "<div align='left'>", $tekst);$tekst = str_replace("[/left]", "</div>", $tekst);$tekst = str_replace("[right]", "<div align='right'>", $tekst);$tekst = str_replace("[/right]", "</div>", $tekst);//So for spaceing you will need something like this :$tekst = str_replace(array("\r\n", "\n", "\r"), '<br>', $tekst); //To create a link of the type [url=http://www.w3schools.com/]W3schools[/url]$tekst= str_replace("[url=","<a location='blank' href='",$tekst);$tekst= str_replace("]","' >",$tekst);$tekst= str_replace("[/url]","</a>",$tekst);// If You Want to add an image too:$tekst= str_replace("[img=","<img src='",$tekst);$tekst= str_replace("]","' />",$tekst);// Underline, bold and Italic text:$tekst= str_replace("[b]","<strong>",$tekst);$tekst= str_replace("[/b]","</strong>",$tekst);$tekst= str_replace("[i]","<i>",$tekst);$tekst= str_replace("[/i]","</i>",$tekst);$tekst= str_replace("[u]","<u>",$tekst);$tekst= str_replace("[/u]","</u>",$tekst);// Set the color of a text:$tekst= str_replace("[color=","<font color='",$tekst); //closing this tag is set for [url]$tekst= str_replace("[/color]","</a>",$tekst);return $tekst;}$result = mysql_query("SELECT * FROM table ORDER BY `id` DESC LIMIT 0, 10");while($row = mysql_fetch_array($result)){echo "<div style='color: black; background-color: lightgreen; padding: 2px; border: 1px solid lightgreen;'>";echo "<div style='width: 70px; float: left;'>";echo "<a href='mailto:".$row[email]."'>".$row[navn]."</a>";echo "</div>";echo "<div style='width: 68px; float: right;'>";echo $row[dato];echo "</div>";echo "<br />";echo "<br />";$kommentar = bbcode($row[kommentar]);echo $kommentar;echo "</div>";echo "<br />";echo "<br />";}mysql_close($con);?> Thibo_1025 Link to comment Share on other sites More sharing options...
Anders Moen Posted February 2, 2007 Author Share Posted February 2, 2007 Yeah. That's how I've tried it, but when I add on that strip_tags thing, the other things there doesn't work :S Then it just shows XHTML in the browser like at learning sites like W3Schools (in their examples). For example, if someone types text it works fine for me. But when I put on strip_tags to make them not ###### up my site by for example adding <html><head><title>lol</title></head><body>HAHAH</body></html> so I get it twice and it's not Valid XHTML 1.1 anymore. THIS IS MY POST 200 Link to comment Share on other sites More sharing options...
justsomeguy Posted February 5, 2007 Share Posted February 5, 2007 Answer my question instead :)Hehe, I'm just joking, but I really need to find out and I can't figure it out myself =/I didn't see a question, you just said it didn't work. What is the problem? Link to comment Share on other sites More sharing options...
Anders Moen Posted February 5, 2007 Author Share Posted February 5, 2007 Actually, you can just forget the whole thing :)Because someone I know from Sweden sent me a much more advanced one, that actually works like I want it to :)I can post it later. I have to find it first lol. My messy computer Link to comment Share on other sites More sharing options...
thibo1025 Posted February 16, 2007 Share Posted February 16, 2007 otherwise I have a problem...I have Two functions: //Function to fix php errors.function fix($tekst) {$tekst = str_replace("<","<",$tekst);$tekst = str_replace(">",">",$tekst);$tekst = str_replace('"','\"',$tekst);$tekst = str_replace("\'", "'",$tekst);$tekst = str_replace("\\", "\\",$tekst); // I know that one is useless but it sorts aout fine like this.$tekst = str_replace("amp;","&",$tekst);return $tekst;} and //BBcode function.function bbcode($tekst){// Alignment of a text:$tekst = str_replace("[center]", "<div align='center'>", $tekst);$tekst = str_replace("[/center]", "</div>", $tekst);$tekst = str_replace("[left]", "<div align='left'>", $tekst);$tekst = str_replace("[/left]", "</div>", $tekst);$tekst = str_replace("[right]", "<div align='right'>", $tekst);$tekst = str_replace("[/right]", "</div>", $tekst);//So for spaceing you will need something like this :$tekst = str_replace(array("\r\n", "\n", "\r"), '<br>', $tekst); //To create a link of the type [url=http://www.w3schools.com/]W3schools[/url]$tekst= str_replace("[url=","<a location='blank' href='",$tekst);$tekst= str_replace("]","' >",$tekst);$tekst= str_replace("[/url]","</a>",$tekst);// If You Want to add an image too:$tekst= str_replace("[img=","<img src='",$tekst);$tekst= str_replace("]","' />",$tekst);// Underline, bold and Italic text:$tekst= str_replace("[b]","<strong>",$tekst);$tekst= str_replace("[/b]","</strong>",$tekst);$tekst= str_replace("[i]","<i>",$tekst);$tekst= str_replace("[/i]","</i>",$tekst);$tekst= str_replace("[u]","<u>",$tekst);$tekst= str_replace("[/u]","</u>",$tekst);// Set the color of a text:$tekst= str_replace("[color=","<font color='",$tekst); //closing this tag is set for [url]$tekst= str_replace("[/color]","</a>",$tekst);return $tekst;} And I send a text from a form to a file.how should I do it? fwrite($fh, bbcode(fix($tekst))); or fwrite($fh, fix(bbcode($tekst))); Link to comment Share on other sites More sharing options...
Anders Moen Posted February 16, 2007 Author Share Posted February 16, 2007 Hey!I went to BBCode.org, and there I found these BBCodes, and they work fine.I just add them in a file called bbcode.php (just example), and then on the site I need them<?phpinclude('bbcode.php');while{echo bbcode($row['name']);}?>And this works just fine :)You can try it here Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now