[support] String conversion

Warren Vail warren at vailtech.net
Mon Apr 11 00:48:56 UTC 2011


Austin,

The only time you need to escape a character in a string, is when it 
would otherwise be miss interpreted.  When you begin a string with a ' 
or a ", PHP will identify the next ' or " as the end of the string, as 
long as it matches the first character.  In other words beginning a 
string with a ' will cause PHP to expect the next ' to mark the end of 
the string (same matching on the " character, if that's what you started 
with).  If you begin your string with a ' (single quote) you can code as 
many " (double quotes) as you want between the first and end string 
character without having to escape them (\ character), conversely if you 
begin your string with " (double quote) you can use as many single 
quotes as you want between them.

If you find yourself having to begin a string with a double quote and 
you absolutely need to imbed a double quote in the middle of the string 
and don't want it to be miss interpreted as the end of the string simply 
precede it with the backslash, to escape it from being miss interpreted 
as the end of string.

On another note, the SQL language used by databases is not PHP, so to 
place SQL syntax in your program so that you can pass it to the SQL 
server, you should place it in a string.  In this case, as you would 
suspect, your string should begin and end with a single quote or a 
double quote.

hope this helps,

Warren Vail

On 4/10/2011 5:23 PM, Austin Einter wrote:
> Hi
> I have a below string.
> *PHP, HTML, SQL*
> Want to convert it to
> *'PHP', 'HTML', 'SQL'*
> I tried to write a function to do it as below. If I print the function 
> output it prints properly.
> If same function output I use for SQL query as below I get warning.
> Query:    SELECT skillid FROM {resubmt_skills}   WHERE 
> resubmt_skills.skillname IN (%s)", $fSkill
> Warning:   SELECT skillid FROM resubmt_skills WHERE 
> resubmt_skills.skillname IN (\'ITI\',\' PHP\'))) in 
> C:\MyWeb6.20\wamp\www\livejobs1\sites\default\modules\resume_search\resume_search.module 
> on line 140.
> Looks it has extra forward slashes. How can I overcome this.
> Thanks
> Austin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110410/bcc44ba1/attachment.html 


More information about the support mailing list