Welcome to Geeklog, Anonymous Monday, May 06 2024 @ 07:00 pm EDT

Geeklog Forums

A PHP Question


Interested

Anonymous
I\'m afraid this will be such a dumb question I\'ll be ashamed to return to these forums. But I can\'t resist. Having some difficulty understanding how to handle string variables. Let\'s say we have the following: $STRINGVAR = \'text group1 with \"double quotes\"\' . $stringvar1; If stringvar1 = \'Jim\'s BBQ\' it causes problems. Is there a way to define $stringvar1 so that PHP doesn\'t mistake the single quote in Jim\'s to be a terminating quote in the overall argument? I\'m I making sense? Should I go back on my meds?
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
There are several ways to get around this. Instead of listing them, may I point you to the PHP manual instead? bye, Dirk
 Quote

Interested

Anonymous
Quote by Dirk: There are several ways to get around this. Instead of listing them, may I point you to the PHP manual instead? bye, Dirk
Uh...thanks. I actually read the manual here. I don\'t think I understood it very well. I will be using an input variable that must allow for such things as single quotes. I tested my code by directly specifying a string with a value that contains a single quote. The code broke. When the single quote was removed, it worked perfectly. I\'m not putting something together here. Ill just keep at it. Thanks again.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by Interested:I will be using an input variable that must allow for such things as single quotes. I tested my code by directly specifying a string with a value that contains a single quote.
To use quotes within a quoted string, you need to escape it, e.g.
Text Formatted Code
'Joe\'s Bar'
. However, when you use an input field and magic_quotes is on in your PHP config, then it's escaped automatically for you ... bye, Dirk
 Quote

All times are EDT. The time is now 07:00 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content