Jump to content

Making the value of a variable not relevant to the rest of the php code?


Allenph9

Recommended Posts

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!

Link to comment
Share on other sites

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 []

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 '

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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()

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.