Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 17-09-2003, 03:41 PM
DingDang's Avatar
Normal User
 
Join Date: Jul 2001
Location: eRakan.Net
Posts: 118
Rep Power: 92
DingDang is on a distinguished road
Send a message via ICQ to DingDang Send a message via Yahoo to DingDang
Question auto escape double quotes in php. anyone?

so, as u can see from my forum, erakan.net, now i'm using PHPNuke as my backend. as a newbie in PHP, here is my question :

does PHP support auto escape for double quotes? like in Perl, i used to write :

$myvar =qq~i can use "as" many as """"double"""" quotes in here bcoz perl have qq = that is stand for "Double Quote"~;

but with PHP, i saw many people are using something like this :

$myvar = "i have to \"be\" carefull here so i don't forget to escape my \"double\" quotes!";

any info?

thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 17-09-2003, 04:28 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
\x is the character escape way for PHP.

I think php functions: htmlentities() and html_entity_decode() are what you want.
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 17-09-2003, 04:32 PM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 97
sufyan is on a distinguished road
In php, you can't use your double quotes like in Perl or ASP, but what you can do is use "double quotes" with 'single quotes'. For example:

PHP Code:
$var 'This "is" an example!';
echo 
$var
or the other way around also works.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 17-09-2003, 04:51 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
suryan is right.

note: variable will not be printed as its value in between single quote.

PHP Code:
$a "variable";
$var 'This "is" a $a!';
echo 
$var
the result will be: This "is" a $a!
,and Not: This "is" a variable!
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 18-09-2003, 12:16 AM
DingDang's Avatar
Normal User
 
Join Date: Jul 2001
Location: eRakan.Net
Posts: 118
Rep Power: 92
DingDang is on a distinguished road
Send a message via ICQ to DingDang Send a message via Yahoo to DingDang
yup.. that is a problem when we use single quotes instead of double. urmm.. do we need to escape single quotes when using single quotes? :/

anyway, i don't think using htmlentities() is a perfect choice for this case because it will convert quote to html code, and that is not we want. what if the variable is holding a code for form?

so, is there any \"easy\" aproach escaping the quotes in PHP without manually doing it and mess the whole HTML codes with \"escape quote\"?

i really miss my qq in perl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 18-09-2003, 01:02 AM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
"do we need to escape single quotes when using single quotes?" -- I think so.

you already knew the 'easy' way. ( \" )
dun be lazy lah~ :P

U use so many quotes until need a lazy way to do it? hehehe...
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 18-09-2003, 01:27 AM
DingDang's Avatar
Normal User
 
Join Date: Jul 2001
Location: eRakan.Net
Posts: 118
Rep Power: 92
DingDang is on a distinguished road
Send a message via ICQ to DingDang Send a message via Yahoo to DingDang
i see.. so that is the only way of doing quote thingy in PHP.

Quote:
U use so many quotes until need a lazy way to do it? hehehe...
no larr.. i just curious because PHP said to be EASY and FASTER (in term of programming), but if i want to build a form, WAAAWIII!!!, \"i\" \"really\" \"need\" \"something\" \"to\" \"automagically\" \"escape\" \"this\" \"!\"\"!\"\"!\"

second, it really mess out the codes. like when u use visual basic and need to insert a variable using & var & inbetween the string... that is soooooooooooooooo annoying!

PHP need to have qq like Perl does. if they can think about htmlentities(), why not move one step ahead and introduce qq...

anyway, i welcome myself to the world of PHP.. and my first step is to create a macros for auto \"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 18-09-2003, 08:12 AM
MHR's Avatar
MHR MHR is offline
Senior Webmaster
 
Join Date: Sep 2001
Location: epox
Posts: 435
Rep Power: 96
MHR is on a distinguished road
Send a message via ICQ to MHR Send a message via Yahoo to MHR
kalau aku la, aku disable magic gpc then just addslashes kat form tu punya value before inserting into db. tak yah la tulis \"
__________________
Munzir + "/^[Hh](a)(z)\1\2[iI]$/"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 18-09-2003, 08:13 AM
MHR's Avatar
MHR MHR is offline
Senior Webmaster
 
Join Date: Sep 2001
Location: epox
Posts: 435
Rep Power: 96
MHR is on a distinguished road
Send a message via ICQ to MHR Send a message via Yahoo to MHR
PHP Code:
function slash_array(&$array)
    {
        if(
is_array($array))
        {
            if (
get_magic_quotes_gpc () == "0")
            {
                
reset($array);
                while(list(
$key,$val)=each($array))
                {
                    if(
is_string($val))
                    {
                        
$array[$key]=$this->addslashes($val);
                    }
                    elseif(
is_array($val))
                    {
                        
$array[$key]=slash_array($val);
                    }
                }            
            }
        }

        return 
$array;
    } 
tak pun guna function ni, so just $_POST = slash_array($_POST);

whatever suits you man... im just giving suggestions
__________________
Munzir + "/^[Hh](a)(z)\1\2[iI]$/"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 18-09-2003, 08:15 AM
MHR's Avatar
MHR MHR is offline
Senior Webmaster
 
Join Date: Sep 2001
Location: epox
Posts: 435
Rep Power: 96
MHR is on a distinguished road
Send a message via ICQ to MHR Send a message via Yahoo to MHR
umm, just read the post above, kalau ko nak buat string on the other hand, kena bubuh slash tu manually. haha. tu wajib, takleh lazy˛
__________________
Munzir + "/^[Hh](a)(z)\1\2[iI]$/"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 18-09-2003, 10:02 AM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
Quote:
Originally posted by DingDang
i see.. so that is the only way of doing quote thingy in PHP.

no larr.. i just curious because PHP said to be EASY and FASTER (in term of programming), but if i want to build a form, WAAAWIII!!!, \"i\" \"really\" \"need\" \"something\" \"to\" \"automagically\" \"escape\" \"this\" \"!\"\"!\"\"!\"

second, it really mess out the codes. like when u use visual basic and need to insert a variable using & var & inbetween the string... that is soooooooooooooooo annoying!
What is the posibilty you will write a sentence like that? Very small, rite. Using \" is faster and easier for NORMAL sentences.

Mess out the code? Never have the feeling yet

welcome to PHP world!
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 18-09-2003, 10:06 AM
DingDang's Avatar
Normal User
 
Join Date: Jul 2001
Location: eRakan.Net
Posts: 118
Rep Power: 92
DingDang is on a distinguished road
Send a message via ICQ to DingDang Send a message via Yahoo to DingDang
itulah maksud aku.... for string

anyway, consider this :

i have a form/html codes that i want to use in my code, so in PERL, i just copy part of the needed codes from HTML and paste it into PERL without loosing my hair (just change the value with variable and thats it) :

so, with Perl i would write something like this:

$myvar =qq~
<center><b>WOHOO</b><br><br>"I want to say something!"<br><br>
<form action="modules.php?name=$module_name" method="post"><input type="hidden" name="who" value="$username"><input type="hidden" name="op" value="broadcast"><input type="text" size="60" maxlength="255" name="the_message">&nbsp;&nbsp;<input type="submit" value="SEND"></form></center>
~;

but with PHP...

$myvar = "<center><b>WOHOO</b><br><br>\"I want to say something!\"<br><br><form action=\"modules.php?name=$module_name\" method=\"post\"><input type=\"hidden\" name=\"who\" value=\"$username\"><input type=\"hidden\" name=\"op\" value=\"broadcast\"><input type=\"text\" size=\"60\" maxlength=\"255\" name=\"the_message\">&nbsp;&nbsp;<input type=\"submit\" value=\"SEND\"></form></center>";

that really mess up my code.. i bet u guys will love the qq function in Perl if u do a lot of strings in ur code.

i have searched the net and failed to find the answer... i guess i have to email a request to zend people... but they are in Israel, which, of course, I hate... so, i guess i have to live with it.

thanx again people.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 30-11-2003, 02:39 PM
Novice Webmaster
 
Join Date: Nov 2003
Location: malaysia
Posts: 25
Rep Power: 0
alien3d is on a distinguished road
Send a message via MSN to alien3d Send a message via Yahoo to alien3d
takyah bubuh kan senang
e.g
print"<form method=post ...";
Aku buat program tak bubuh quote
Tetapi kalau nak masuk database
Katakan <input name=x value=j"jlkjdjfld" >
Kena convert dulu
$c=$x
insert into $c $table
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 30-11-2003, 04:33 PM
hymns's Avatar
Senior Webmaster
 
Join Date: Nov 2001
Location: Johor
Posts: 769
Rep Power: 101
hymns is on a distinguished road
Send a message via ICQ to hymns Send a message via Yahoo to hymns
walalala... dak sowang ni...
Oooo en mahluk asing 3d... angpa paham dok diorang bincang about ape? kalau dok tgk post yg bawah tu jo, tak yo la nyampuk. tapi ikut suka hang la kan? ehhee

aler yg form tu, gune je single quote tak leh ke dingdang? yg nak guna quote tu lotakkan je ha slash.. don't lazy˛ lah...

yak! yak! selamat hari ghaye!
__________________
I hate when:

vBulletin Message:
Sorry! The administrator has specified that users can only post one message every 60 seconds
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 30-11-2003, 09:21 PM
Ben-davis's Avatar
Senior Webmaster
 
Join Date: Jan 2002
Location: SoObHanG JhaYa
Posts: 501
Rep Power: 94
Ben-davis is on a distinguished road
Send a message via ICQ to Ben-davis Send a message via Yahoo to Ben-davis
ahaha.... ni musti penin kes makan lemang banyak sangat,.,,,
__________________
<form name="jump">
<select name="menu" onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" style="border:1px #393F31 solid;color:#393F31;font:10px Verdana;font-weight:bold;" >
<option value="0" style="background: #9CC8FE" selected>*SELECT-LINKS</option>
<option value="http://www.gengturbo.org/" style="background: #FF0000">GENGTURBO</option>
<option value="http://www.phixelgrafix.com/" target="new" style="background: #C6D607">PHIXELGRAFIX</option>
<option value="http://dailydigital.phixelgrafix.com/" style="background: #FCBC45">OLD-BLOG</option>
<option value="http://www.mesrahosting.net/" style="background: #FF99CC">WEBHOSTING</option>
</select>
</form>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

<