Allenph9 Posted March 4, 2012 Share Posted March 4, 2012 So what i mean is if i set a variable to "[" ($some_variable = "[") the rest of my code is now going to go CRAZY because there is an open [. Is there a way I can just make everything inside the first set of "" not relevant to the code? thanks! Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted March 4, 2012 Share Posted March 4, 2012 I'm going to guess that almost noone has any idea what you're even asking. Example code helps the best, but when you say "the code is going to go crazy", you have the describe what you even mean by that. Quote Link to comment Share on other sites More sharing options...
Allenph9 Posted March 4, 2012 Author Share Posted March 4, 2012 I'm going to guess that almost noone has any idea what you're even asking. Example code helps the best, but when you say "the code is going to go crazy", you have the describe what you even mean by that. Well it makes sense. The rest of the code after the [ in my example is going to think it is inside a [] but since i don't provide a ] its going to feed me an error. I want the value of the variable to be [ but for the rest of the code to not assume that it is inside a [] Quote Link to comment Share on other sites More sharing options...
l0gic Posted March 5, 2012 Share Posted March 5, 2012 Exactly what Danny said above. If I had to guess though it's not your [ making things go crazy.. Lets play spot the difference? $some_variable = "[" $some_variable = "["; Posting your code would help a lot. Quote Link to comment Share on other sites More sharing options...
Allenph9 Posted March 5, 2012 Author Share Posted March 5, 2012 Exactly what Danny said above. If I had to guess though it's not your [ making things go crazy.. Lets play spot the difference? $some_variable = "[" $some_variable = "["; Posting your code would help a lot. my apologies...the [ character would not do anything your right. I meant something more like " or ' Quote Link to comment Share on other sites More sharing options...
l0gic Posted March 5, 2012 Share Posted March 5, 2012 I meant something more like " or ' Using a back-slash will 'escape' these characters. $string = "It's not \"that\" bad!"; Quote Link to comment Share on other sites More sharing options...
Allenph9 Posted March 5, 2012 Author Share Posted March 5, 2012 I did try something like that...but its a bit complicated and won't work with what I am trying to do. I'm making a forum and I have set up my page to make a new page that will contain the thread. I have it set up so it fwrites some variables pertaining to what will be displayed at the top. then later they are echoed to print picture content text etc. I tried making the first page write "<?php $thread_body =\" . $_POST['thread_body'] . "\"; ?>" that works just fine for the thread title and picture paths etc...but I don't allow users to put <> or " or ' in the title or the paths. as soon as someone puts " or ' or anything like that my code thinks it is inside this " or '. I tried to counteract it with replacing all of those characters with /the character but for some reason the oage didnt like that. sooo Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted March 5, 2012 Share Posted March 5, 2012 Sorry, I still have no idea what you're trying to accomplish and what going wrong in the process. I gather you want some kind of script to read what's in between a '[' and ']'? Like with bbcode? But even if that's the case, I don't understand your problem enough to be able to help. Just post a piece of your code where it's not acting like you want it to act, explain what you want it to do, and explain the wrong output/error you're getting, then we can probably help. Quote Link to comment Share on other sites More sharing options...
l0gic Posted March 5, 2012 Share Posted March 5, 2012 Ok, now we're getting somewhere! I'd like to introduce you to your new best friend htmlentities(), you would use it when inserting the thread title/body/etc into your database. <?php $str = "A 'quote' is <b>bold</b>"; // Outputs: A 'quote' is <b>bold</b> echo htmlentities($str); // Outputs: A 'quote' is <b>bold</b> echo htmlentities($str, ENT_QUOTES); ?> If you copy and paste either of those into an HTML page you'll see it converts < to < and so on. Also.. <?php $thread_body =\" . $_POST['thread_body'] . "\"; ?> is doing it wrong, you only need to use <?php $thread_body = $_POST['thread_body']; ?> You would only need to use quotes there when assigning a string to the variable, like.. <?php $thread_body = "This is my thread body!"; ?> Edit: You could also use htmlspecialchars() Quote Link to comment Share on other sites More sharing options...
Allenph9 Posted March 5, 2012 Author Share Posted March 5, 2012 GENIUS! thank you that worked perfectly! Quote Link to comment Share on other sites More sharing options...
l0gic Posted March 5, 2012 Share Posted March 5, 2012 GENIUS! thank you that worked perfectly! No problem, make sure you understand those functions though. There is information and examples on both here: http://php.net/manual/en/function.htmlentities.php http://php.net/manual/en/function.htmlspecialchars.php Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted March 5, 2012 Share Posted March 5, 2012 well good thing someone understood Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.