Php Long Variables - How do you make them?

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Php Long Variables - How do you make them?

sparkx
Don't ask why but I need to make a long variable that contains ' " ; and ) meaning I cannot use:
CODE
$var=('Test');

It will create an error. Here is an example of what I am talking about:
CODE
$var=("I want to use ' and " while allowing html and not using htmlspecialchars");

Basicly is what I want is a <<<END variable. I know you can do this in an echo like:
CODE
echo<<<END
This is some echo. I can use ' " ) and; without using htmlspecialchars
END;

Is there a way to make a simalur code that works with variables? Do you get what I mean? That would really help me out.
Thanks,
Sparkx
Note: I need it for HTML and some HTML strings use both ' and " so I cannot use just one and make the string with the other.

 

 

 


Reply

pyost
According to php.net, there are only three ways of storing a string. The first one uses single quotes, the second one double quotes, and the third one uses the heredoc structure (<<<END ... END;). There are slight difference between the first two when it comes to escaping, but either way you would have to use \' or \". I think that heredoc is your best option, as it doesn't require any escaping and you can insert variables without any problems. Yes, it is somewhat bulky, but is great for outputting HTML code.

Reply

TavoxPeru
You can use the Chr() php function, this function returns a one-character string that contains the character specified by the ascii code passed to the function as a parameter.

For example try this code:
CODE
$var=chr(40) . chr(39) ."Test" . chr(39) . chr(59) . chr(41);
echo $var;


You can get all the ascii codes with the following function:
CODE
for($x=32; $x<256;$x++) {
echo "code = $x : char = " . chr($x) . "<br />";
}

I start the for with the value 32 -it is the space character- because all the prior characters are control characters that you don't need i guess, if you want change it to 1 and see what i'm talking.

BTW, sorry but right now i don't have more time to test if it would work fine with HTML code, maybe later i can.

Best regards,

 

 

 


Reply

sparkx
Thanks pyost and voxPeru. I am going to look at php.net for the <<<END and END; method for a string. If that does not work I many need to use the advanced looking chr() string. I know a little about the <<<END method and how it stops most php enjections ect.
Thanks again,
Sparkx

Reply

vujsa
I'm not sure if you ever got the answer that you needed. It is possible to simply escape the problematic quote like so:
CODE
$var = "That's the \"BEST\" option I have ever seen!";
echo $var;
Outputs:
Thats' the "BEST" option I have ever seen!

--OR--

CODE
$var = 'That\'s the "BEST" option I have ever seen!';
echo $var;
Outputs:
Thats' the "BEST" option I have ever seen!

--OR--

You can of course do it the easy way which is to use the heredoc method:
CODE
$var = <<<EOD
Thats' the "BEST" option I have ever seen!
EOD;
echo $var;
Outputs:
Thats' the "BEST" option I have ever seen!


For more information, here is a link to the PHP.net syntax for this option:
http://php.net/manual/en/language.types.st....syntax.heredoc

I hope that this helps you out. cool.gif

vujsa

Reply

vizskywalker
Cool. I didn't know you could use heredoc to define variables. I never assumed you couldn't, just never thought about it. Useful to know.

~Viz

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Recent Queries:-
  1. passing "long variables" in php - 1.32 hr back. (1)
  2. php long type - 6.63 hr back. (1)
  3. php variable characters maximum - 13.83 hr back. (1)
  4. [php] long variable - 30.29 hr back. (1)
  5. php (long) variable types - 33.87 hr back. (1)
  6. how long variable php - 34.20 hr back. (1)
  7. long long data type php - 38.86 hr back. (2)
  8. php long variables - 49.66 hr back. (2)
  9. php long variable - 9.99 hr back. (2)
  10. php long - 20.69 hr back. (3)
  11. long php - 76.77 hr back. (1)
  12. php chr to long - 86.61 hr back. (1)
  13. php declare variable as long - 98.56 hr back. (1)
  14. variables php long - 99.80 hr back. (1)
Similar Topics

Keywords : php, long, variables, make,

  1. Quickly Create Form Variables
    simple form, variable creation, referer check, safe guard variables (5)
  2. User Authentication Session Handling Problems
    Authorization server variables not staying across pages (14)
    This is quite a bit of problem I am facing, and I cannot point exactly where I am going wrong. I
    have been lurking around here at the Asta Host forums with regard to login and user authentication
    scripts and I have got as far as this: - Starting a session - Registering a session variable -
    Using the variable to check if the user is authenticated or not. - Authenticating the user through
    MySQL database - Logging of the user, by setting the session variable to un-authenticated I have
    been able to achive the following things too that I think is not related to this proble....
  3. Php : Variables Included Dont Work In Functions
    Variables from Included files dont work (4)
    Today, I came up with this strange PHP behaviour. Just wanted to know if anyone has any
    suggestions! I make a common variable/function file called config.php. I put in my generally used
    functions in it. Suppose this is my file // -----VARIABLES --- // $a=10,$b.... //
    -----FUCTIONS--- // function doit() { print "A value is " . $a; } ?> Here, suppose we execute
    this file directly. Since A has a global scope, it does work perfectly. But if this same file is
    imported in another file say, mainfile.php // -----VARIABLES --- // $c,$d.... include
    'config.ph....
  4. Question On Depecrated Tracking Variables In Php
    (2)
    It seems I can no longer use the line... it returns an error saying this: Warning: is no
    longer supported - please use the track_vars INI directive instead in on line 1 So what do I
    replace the track_vars command with? O_o Any help would be appreciated.....

    1. Looking for php, long, variables, make,






*SIMILAR VIDEOS*
Searching Video's for php, long, variables, make,
advertisement




Php Long Variables - How do you make them?