|
|
|
| Web Hosting |
![]() ![]() |
Php Long Variables, How do you make them? |
Aug 16 2007, 03:28 PM
Post
#1
|
|
|
Sparkx Group: [HOSTED] Posts: 371 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 myCENTs:0.61 |
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. |
|
|
|
Aug 16 2007, 07:45 PM
Post
#2
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 1,053 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 myCENTs:36.94 |
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.
|
|
|
|
Aug 17 2007, 06:34 PM
Post
#3
|
|
|
Super Member Group: [HOSTED] Posts: 818 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:3.57 |
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, |
|
|
|
Aug 20 2007, 03:14 PM
Post
#4
|
|
|
Sparkx Group: [HOSTED] Posts: 371 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 myCENTs:0.61 |
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 |
|
|
|
Oct 2 2007, 12:48 AM
Post
#5
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 myCENTs:35.43 |
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!"; Outputs:echo $var; Thats' the "BEST" option I have ever seen! --OR-- CODE $var = 'That\'s the "BEST" option I have ever seen!'; Outputs:echo $var; 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 Outputs:Thats' the "BEST" option I have ever seen! EOD; echo $var; 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. vujsa |
|
|
|
Oct 2 2007, 01:58 AM
Post
#6
|
|
|
Techno-Necromancer Group: Members Posts: 1,018 Joined: 13-January 05 From: The Net Member No.: 2,127 |
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 |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
0 | xboxrulz | 104 | 29th November 2008 - 08:37 PM Last post by: xboxrulz |
|||
![]() |
5 | yordan | 779 | 6th November 2008 - 09:52 AM Last post by: yordan |
|||
![]() |
1 | livingston | 474 | 29th August 2008 - 02:49 AM Last post by: Running With Scissors |
|||
![]() |
29 | chris1234 | 2,863 | 14th May 2008 - 09:09 PM Last post by: Darasen |
|||
![]() |
4 | OpaQue | 1,320 | 25th March 2008 - 10:08 PM Last post by: Umar Shah |
|||
![]() |
15 | mtl8 | 2,361 | 3rd February 2008 - 08:23 PM Last post by: Ggadget |
|||
![]() |
99 | miCRoSCoPiC^eaRthLinG | 10,645 | 21st January 2008 - 01:11 PM Last post by: joseph77 |
|||
![]() |
5 | kxrain | 663 | 14th January 2008 - 07:02 PM Last post by: vujsa |
|||
![]() |
84 | sid.calcutta | 5,317 | 27th November 2007 - 10:02 PM Last post by: wutske |
|||
![]() |
11 | valcarni | 1,853 | 7th November 2007 - 04:57 AM Last post by: vujsa |
|||
![]() |
14 | Marcella | 1,869 | 22nd October 2007 - 06:17 AM Last post by: Doveshire Designs |
|||
![]() |
2 | CaptainCPS-X | 1,155 | 25th September 2007 - 08:41 PM Last post by: polarysekt |
|||
![]() |
6 | dserban | 667 | 20th September 2007 - 07:34 AM Last post by: Sten |
|||
![]() |
5 | demolaynyc | 1,225 | 9th July 2007 - 10:40 AM Last post by: lonelym |
|||
![]() |
23 | wutske | 1,853 | 7th July 2007 - 11:51 AM Last post by: Sweet Impact |
|||
|
Lo-Fi Version | Time is now: 8th January 2009 - 01:10 AM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Aug 16 2007, 03:28 PM






