Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Quotation Marks inside a declared variable
Old 09-08-2007, 08:49 AM Quotation Marks inside a declared variable
Yak Yak Yak Yak Yak

Posts: 593
Location: Rochester, MN
Trades: 0
$variable = "Some text goes here, but when there are "quotation marks" in the text, it throws up an error";

The variable is declared in a script that I have no editing access to. Does anyone know how to remove the quotes from the variable after it has been passed to the script? Using the variable as stated above, is there a function I could use to do this? Something like: variable = function_name("Some text goes here, but when there are "quotation marks" in the text, it throws up an error");

I keep getting the "unexpected t string" error.

Please don't tell me I can use str_replace to replace the quotation marks. When they cause the error, they are already declared in the script, and I have no access to input a str_replace at the source (before it's imported with the quotes inside the variable).
__________________

Please login or register to view this content. Registration is FREE
neorunner is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-08-2007, 09:00 AM Re: Quotation Marks inside a declared variable
Skilled Talker

Posts: 62
Name: Tom Wright
Location: Brighton, UK
Trades: 0
The problem is that the string is ended when it reaches the first " after the one that opened it. So in the example you give $variable will be set to "Some text goes here, but when there are" and the following word ("quotation") is therefore an unexpected string because you've not said what to do with it.
The solution would be to 'escape' your internal quotation marks using a backslash (\):
PHP Code:
$variable "Some text goes here, but when there are \"quotation marks\" in the text, it throws up an error"
or to use single quotation marks to define your variable:
PHP Code:
$variable 'Some text goes here, but when there are "quotation marks" in the text, it throws up an error'
I hope this helps, Tom
__________________
My site:
Please login or register to view this content. Registration is FREE
tomythius is offline
Reply With Quote
View Public Profile
 
Old 09-08-2007, 01:00 PM Re: Quotation Marks inside a declared variable
damien_ls's Avatar
Layershift

Posts: 474
Name: Damien
Trades: 0
Where do the quotes come from, and what is it used for?

Would it make sense to encode them as HTML entities instead - e.g. htmlentities - or if not, how about addslashes?
__________________

Please login or register to view this content. Registration is FREE
:: DDS & Dedicated, UK & USA-based
Please login or register to view this content. Registration is FREE
, Reseller & Shared Hosting
Experienced Parallels Platinum Partners (Plesk since 2001, Virtuozzo since 2003)
damien_ls is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Quotation Marks inside a declared variable
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11893 seconds with 12 queries