Difference Between Single And Double Quote String?

Mar 11, 2011

Difference between single quote and double quote string in php. What is the difference between echo 'Test Data'; and echo "Test Data"; in PHP. Both statements give me same output.

ADVERTISEMENT

Difference Between Single Quote And Double Quote String?

Aug 10, 2010

I'm not a major in PHP programming but I'm a little confused why I see some codes in PHP with string placed in single quote and sometimes in double quote. I just know in .NET, or C language, if it is in single quote, that means it is a character, not a string.

View 7 Replies View Related

String - Convert Single Quote To Double Quote In All HTML Tags?

May 28, 2009

How can I convert all single quotes to double quotes in all HTML tags only? Is there an easier way to do it?

For example: How can I convert this string (actual data from my work):

<TEXTFORMAT LEADING='2'><P ALIGN='LEFT'><FONT FACE='Verdana' style="font-size:10' COLOR='#0B333C'>My name's Mark</FONT></P></TEXTFORMAT>

To this:

<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style="font-size:10" COLOR="#0B333C">My name's Mark</FONT></P></TEXTFORMAT>

View 6 Replies View Related

String Parsing - Double Quotes - Single-quote

Jul 17, 2005

I am trying to build a where clause for mysql based on different form inputs but php seems to have a problem with the following:

$whrClause = "WHERE keywords LIKE '%$keywords%'"

I thought with the double quotes that the single-quote and percent signs would remain unchanged and the variable $keywords would be expanded to its value, but I guess I am wrong because i get a parsing error.

View 3 Replies View Related

Single Versus Double Quote Marks As String Delimiters

Jul 17, 2005

I have heard other people say that PHP can parse double quoted strings
(e.g., "Hello, World") faster than it can parse single quoted strings (e.g.,
'Hello, World'). This seems backwards to me, since double quote strings
have to be checked for any variables that need to be interpreted, whereas
single quoted strings do not.

So, what is the truth on this matter? And the explanation?

View 12 Replies View Related

Add Single Quote Or Double Quote If Content Have A White Space?

Feb 2, 2011

I try to make dynamic CSS using PHP.

Example on font-family

$one = 'Times New Roman, Times, serif';
$two = 'Lucida Sans Unicode, Lucida Grande, sans-serif';
On style.php
body { font-family:<?php echo $two; ?>; }

Here I want to add a single quote or double quote to the Lucida Sans Unicode, Lucida Grande

So the ouput should be

body { font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif; }

Let me know how to replace the font with a quote

View 5 Replies View Related

How Do You Interpret Single Quote Embedded In Double Quote Embedded In Single Quote?

Jul 28, 2007

I got the following example from http://www.evolt.org/article/User_F...0144/index.html
:

echo '<tr><td>First name:</td><td><input type="text" name="first_name"
value="'.htmlspecialchars($_POST['first_name']).'"></td></tr>'

What purpose do the single quotes serve in
value="'.htmlspecialchars($_POST['first_name']).'"

View 2 Replies View Related

Single/double Quote

May 5, 2003

why are the escaped " (double quotes) printed with the variable? PHP Code:

View 9 Replies View Related

Best To Use Single Or Double Quote For Forming Strings?

Feb 18, 2006

Here's something I've been wondering. Do most of you use single or
double quotes as a string encapsultor?

ex:
$s = "This is a string, I can embed ' with no prob";
vs.
$s = 'This is a string, I can embed " with no prob'

Is there an advantage or best-practice reason to choose one over the other?

View 2 Replies View Related

Find A Single Or Double Quote In $desc That Was Not Escaped.

Oct 30, 2006

I am having problems getting php to escape characters, so I can use them with javascript. Here is the code. PHP Code:

$desc = $item['description'];

$desc = str_replace("'", "'", $desc);
$desc = str_replace('"', "'+String.fromCharCode(34)+'", $desc);

echo "<a href='index.php' onMouseover="showTooltip(event,'$desc');return false">Link</a>";

I am trying to get a tooltip to work. It seems to work most of the time, but sometimes the tooltip does not work, and when that happens I can find a single or double quote in $desc that was not escaped.

View 1 Replies View Related

Addslashes Adding Double Backslashes When Escaping A Single Quote?

Apr 2, 2009

Addslashes seems to be a bit confused. Given the following 2 lines of code

$name = "Dave's test";
$newName = addslashes($name);

I am expecting $newName to be "Dave's test" (my one single quote nicely escaped)

However, what I'm getting is "Dave\'s test" (note the DOUBLE backslashes). This contradicts every bit of online documentation I can find on addslashes - and causing me a lot of grief.

I am dumping the before and after addslashes results to the http error log via error_log...

error_log("before=$name after=$newName");

results...

before=Dave's test after=Dave\'s test

Note - this is part of an ajax process, so I can't really 'echo' the results.

FYI: I'm Using PHP 5.2.6 under linux with magic quotes OFF.

View 6 Replies View Related

Echo Syntax Error With Single Quote Or Double Quotes?

Jun 7, 2010

The is a very simple echo statement but I can't solve it?

echo '"What is your name?'";

View 6 Replies View Related

Difference Between Single And Double Quotes

Dec 23, 2006

i understand about the difference between single and double quotes, but are there any benefits of using single quotes other than the speed? and is this speed difference worth while? also, why do double quotes slow the process down?

View 5 Replies View Related

Extract A String From Double Quote?

Jun 19, 2009

I have a string

This is a text, "Your Balance left $0.10", End 0

how can i extract the string in between double quote and have only the text 'Your Balance left $0.10' (without the double quotes)

Tried preg_match_all but no luck

View 6 Replies View Related

Use Quote Escapes For Single Quotes Or Use Double Quotes In Arrays?

Feb 23, 2010

I realized that I can have problems with single quotes in php arrays:

<?php
$lang = array(
'tagline' => 'Let's start your project',
"h1" => "About Me"
);
?>

So I changed it to double quotes:

<?php
$lang = array(
"tagline" => "Let's start your project",
"h1" => "About Me"
);
?>

Should I use "php quote escapes", instead of what I just did? (by the way how to write "php quote escapes"?)

View 2 Replies View Related

Strpos() Fails To Find Double Quote ('"') In String?

Jan 31, 2010

Both this:

echo 'Tok: '.$tok.' Strpos: '.strpos($tok, """).' length: '.strlen($tok).'<br>';
And this:
echo 'Tok: '.$tok.' Strpos: '.strpos($tok, '"').' length: '.strlen($tok).'<br>';

Result in the following output:

Tok: "fresh Strpos: length: 11

Strpos is failing completely to find the double quote, it returns false (I checked with strpos() === false). Can someone tell me what's going on here? I can find no documentation suggesting that strpos can't handle double quotes, why isn't it finding it? I am at my wits end.

View 4 Replies View Related

Removing Single-quote From A String?

Oct 11, 2010

I have an HTML form that a user can input text into a title field, I then have php creating an HTML file called title.html My problem is that users can input spaces and apostrophes into the title field that can't be used in the html file name. I replaced the spaces with underscores by using:

$FileName = str_replace(" ", "_", $UserInput);

However, I can't seem to remove single-quotes? I have tried using:

$FileName = preg_replace("/'/", '', $UserInput);

but this took test's and turned it into tests.html.

View 3 Replies View Related

Find String With Single Quote?

Apr 18, 2011

I have an array of strings . I need all the strings which do not contain any special character. Only a to z is allowed. Is there any method using regex or is there any string function ?

View 2 Replies View Related

Javascript String With Single Quote Printed From Code?

Jul 13, 2011

I have following script printed from PHP . If some one has a single quote in description it shows javascript error missing ; as it thinks string terminated .

print "<script type="text/javascript">
var Obj = new Array();[code]....

Form does a post to this page and title and description comes from textbox.Also I am unable to put double quotes around {$_REQUEST['title']} as it shows syntax error . How can I handle this ?

View 3 Replies View Related

Escaping Single Quote Of String Echoed To Input Text Box?

Feb 3, 2010

I need to ouput a last name to a input text box.  The name has a single quote in it.  I can only get the text before the quote to output.  Here is my php code:

echo "<div class='fifteen'>$i. First name:</div><input type='text' value='$firstName' id='$first' name='$first' size='12' />  Last name:$lastName <input type='text' value='$lastName' name='$last' id='$last' size='12' /> Year: ";

The $lastName variable has a single quote in it. I've tried addslashes, stripslashes, and mysql_real_escape_string alone and in combination all to no avail.

View 3 Replies View Related

How To Strip Quotes (single And Double) From A String

Sep 18, 2007

I have used a class called clsMetaContent.php, as provided in the book Creating Interactive Websites with PHP and Web Services, by  Eric Rosebrock - who I understand is the lead developer of this site.

While using this class with my application - I find a problem in the assignment of the description for the description part of the meta tag.

The code in the class looks like this:

// Formulate the description for each page.
      if(empty($ptitle)){
         $description = $this->description;
      } else {
         $description = '$ptitle - $this->description";

I have found that my description can contain single and/or double quotes. Which causes a problem with the assignment of the meta tag for the description. What happens is, due to the error in the format of the meta tad description, it outputs the contents of description again on the start of my web page, instead of keeping it within the meta tag assignment.

I think I just need a function to strip out double and single quotes - but have been unable to find any.

View 8 Replies View Related

Regex For Matching Double And/or Single Quoted Strings Within In A String?

Jul 10, 2010

I'm working on a template class and I've an issue when trying to parse out a list of quoted strings from a string argument list. Take for example the string:

$string = 'VAR_SELECTED, 'Hello m'lady', "null"';

I'm having a problem coming up with a regex that extracts the string "Hello m'lady" and "null". The closest I have got is

$string = 'VAR_SELECTED, 'Hello m'lady', "null", 'TE'ST'';
preg_match_all('/(?:[^']|\\.)+|(?:[^"]|\\.)+/', $string, $matches);
print_r($matches);

[code]...

View 3 Replies View Related

Pre_match Check If String Is Surrounded In Double Or Single Quotes.

Feb 25, 2011

the regex to see if something is surrounded in double or single quotes.

"this is the string"

i want it to return false if it quotes are not present at all or not present at the start and the end.

View 2 Replies View Related

Convert Double Quoted String To Single Quoted Literal String

Jun 15, 2011

Is there a way to convert the double quoted string "<b>foo</b>" to the single quoted string '<b>foo</b>'. note that I cannot use <?php strip_tags("<b>foo</b>")?>, I need to tags to be present. EDIT: I should have asked a question, I would like to styling to be removed, I don't wish foo to be boldened - just for <b>foo</b> to be echo'd to the screen.

View 1 Replies View Related

Single Quoted String Not Equal To Identical Double Quoted String?

Feb 18, 2010

I haven't used PHP since 2007, so I am a bit rusty, but I have come across a strange bug. I am running php 5.2 Non Thread Safe on Windows IIS on vista. Problem is when using single quotes.

if ('hello' == "hello") This returns false
echo stren('hello'); This returns 7
BUT if I do this:- echo strlen("hello"); (which returns 5)
THEN do echo stlen('hello'); (with the single quotes again, returns 5);
AND if ('hello' == "hello") Now returns true;

View 14 Replies View Related

Escape Single Quote Within Single Quotes Query

Jun 29, 2011

I'm trying to write a web scraper for the source code of a webpage. The regex expersssion I'm using is (.+?) which means match everything from here until the delimiter which is a ' character.

$regex = '/&kingdom=(.+?) ' /';preg_match($regex,$data,$match);var_dump($match);echo $match[1];()

The problem is that I can' delimit at the ' character.I've tried escaping it like ' but that doesn't work. How do I use the ' character correctly inside single quotes?

View 7 Replies View Related

Double Quote

Nov 5, 2005

For example, PHP Code:

$res = mysql_query("SELECT * FROM members");
$row = mysql_fetch_array($res);

$username = $row[username];
$username = $row['username'];
$username = $row["username"];

View 1 Replies View Related

Echo Double Quote Problem

May 3, 2006

google and manual do not say much for printing double quotes in a path case.

To facilitate your reading (I don't know how to make it colorful in
newsgroup), i'd appreciate studying the code at:

http://appsrv.cse.cuhk.edu.hk/~kkleung/menu.phps

removing tr, td and using combinations of single and double quotes did not
solve the problem :(

View 3 Replies View Related

Preg_replace Double Quote "

Jun 4, 2003

I'm import .csv files that are delimited in one of the following ways.

"test","test1","test2"
or
test,test1,test2

I can get them both to explode, but I can't get the double quote " removed. Thought that preg_replace might do the trick, but I can't figure out how to get it to find the double quote and replace it with nothing. If there is a better way of fixing the problem or importing the file I'm happy to listen. Re-saving the file is not an option in this case.

View 5 Replies View Related

Write The Value That Has Double Quote And Comma Together To Csv ?

Jun 29, 2009

I need to get columns value from db and write them to CSV.Some of value of column called question has comma, so I did something like this

PHP Code:
fwrite($fp,'"'.$row['question'].'",'); 

to put that value in one column in CSVbut I found some value contains double quote("") and comma together, something likePHP Code: I have "big" quesiton, that I want to know.So if I put the above code logic, it still separate into 2 columns in CSV. First column has

View 4 Replies View Related

Variables - Convert Single Quoted String To Double Quoted

Mar 9, 2011

I have a string returned from a database query which contains variables, however it appears that these strings are all returned single-quoted and therefore the variables are not evaluated as they would be if it was double quoted. what is returned from the sql query would be the $result: This will not evaluate the 2 variables:

$myname = 'david';
$occupation = 'Beginner';
$result = 'Hello my name is $myname and I my occupation is $occupation';
echo $result;

This will evaluate the 2 variables:

[Code]....

My question is how do I convert a single-quoted string to a double-quoted string which is able to evaluate the variables?

View 2 Replies View Related

Passing The Single Quotes And Double Quotes In The String

Jan 25, 2011

'<a href="javascript:void(0)" onClick="function(''.$row['STUID'].'')">Print STUDENT DETAILS</a>';

Is this the correct way of passing single quotes and double quotes in the statement

View 2 Replies View Related

String With Double Quoted And Single Quoted?

Mar 29, 2009

i have a string with double quote like this

$count = 5;
$str = "result: $count";
echo $str; //result: 5

variable parsing work well, and my problem is $count var must be define later than $str

$str = "result: $count";
$count = 5;
echo $str; //result:

So i will use single quote and ask a question here to finding a way to parse var whenever i want

$str = 'result: $count';
$count = 5;
//TODO: parse var process
echo $str; //result: 5

I'm will not using regex replace.

View 3 Replies View Related

Single Quote

Jun 16, 2007

PHP Code:

while($row = mysql_fetch_object($sql_query)){
    $menu_title = $row->menu_title;
}

//First echo
echo $menu_title;

//Second echo
echo"<tr>
  <td ><input type='text' size=&#3930;' name='title' value=".$menu_title."></td>
</tr>";

//Thrid echo
echo"<tr>
  <td ><input type='text' size=&#3930;' name='title' value='$menu_title'></td>
</tr>";

View 1 Replies View Related

Allow To Put Single Quoted - Double Quoted Heredoc Syntax Or Nowdoc Syntax Strings Directly Into A Functions Parameter That Uses A String?

May 24, 2011

Am I allowed to put single quoted, double quoted heredoc syntax or nowdoc syntax strings directly into functions whose parameters require a string like for example strlen('string text') or strlen("some more string text") instead of including a variable for example strlen($str);?

View 3 Replies View Related

Comma's, Dot's, Single Quote

Jul 31, 2007

I had this in my script that inserted values into a MySQL table: ....

View 3 Replies View Related

Pattern Containing Single Quote

Dec 26, 2006

I am stuck at a wierd problem. I am trying to do comparision between a "query string" and a "string value". the string consists of some diacriticals and single quotes. But when i try to escape the single quotes using backshash () it doesnt work. and when i try to use it inside a double quote preg_replace() doesnt recognise the code. why is php not comaparing string with single quotes?

here is the code:
if($_GET['query']==new)
{ filter($query);}
elseif($_GET['query']==some'u'all)
{ filter($query);}
elseif($_GET['query']==all'u'ppl)
{ filter($query);}

function filter($query)
{
$pattern = array ('/new/','/some'u'all/','/all'u'ppl/');
$rep = array ("new way","Some of you all ","all of you");
$op = preg_replace($pattern,$rep,$_GET['query']);

View 2 Replies View Related

Single Quote Search?

Jan 18, 2010

i want to search mc'd in my database,but i use mysql_real_escape_string

but nothing found bcos it will output mc\'d

View 3 Replies View Related

Escaping Single Quote?

Apr 13, 2011

I have an admin page which handles adding of product. I used mysql_real_escape_string on protecting my database from unnecessary characters. But when I get these data from the database (e.g. product name with single quote like Dave's Box), I had a error when displaying it on my page in the onclick attribute.

I used this code for displaying the product code.

echo "<li onClick='fill("$productName")'><strong>".stripslashes($row['name'])."</strong> by ".stripslashes($row['brand'])."</li>";

View 4 Replies View Related

Use Single Quote Vs Back Tic?

Jul 28, 2009

What is the difference between using single quote and back quote?

Code:
SELECT * FROM `db`.'table'
vs
[code]......

View 4 Replies View Related

Class - String The Double Colon And Double Underscore?

Jun 8, 2010

What do you call with these string :: and __ in PHP and what other strings are similar to them?

View 1 Replies View Related

Exec, Single Quote & Security...

Jul 16, 2005

(i'm particulary interested in security issue - php is running on
apache + linux)

i need to pass the result (here $exp) of a form submission to a third
part application using :

exec("echo $exp | third_part", $arr, $ret);

this $exp may contain simple quote such as in "they're" and if i'm
very unlucky harmful code for my system.

by now i use :

$exp = "'" . implode("' ' '", explode("'", stripslashes($exp))) .
"'";

to be sure to maintain single quotes and i also expect to avoid some
common vulnerabilities (by enclosing them inside '')

View 1 Replies View Related

The Amazing Escaped Single-quote

Jun 16, 2000

Say you have a form with a textarea. Say you type something with single-quotes (e.g. I'm happy so I'm sad) in the textarea. When the textarea is POSTed to a PHP program, are they escaped with the backslash?

I ran it on two different servers and one did and one didn't. Why is this? Is there some setting somewhere? Or is this a version diff thing? Here is the PHP code (I changed all angle brackets to square ones so it'll appear): Code:

View 2 Replies View Related

Allowing Single Quote In Preg_match

Oct 11, 2006

I'm trying to validate text in a HTML input field.
How do I *allow* a single quote?

// catch any nasty characters (eg !@#$%^&*()/)
$match = '/^['w.-_?!, ]+$/'
$valid_srch = preg_match($match, $res_description);
if (!$valid_srch) {
...
}

for $match I've also tried:

$match = '/^['w.-_?!, ]+$/'

$match = '/^[&quot;w.-_?!, ]+$/'

$match = "/^['w.-_?!, ]+$/";

$match = "/^['w.-_?!, ]+$/";

and numerous other strings but always ' is seen as an
invalid character.

View 5 Replies View Related

Backslashes Are Being Added Before Every Single Quote

Nov 4, 2006

I am writing a basic PHP news administration system, but am having a little problem. Wherever there is a single quote, a backslash is being added before it. My news system works this way; I have a set of HTML forms on one page that save their contents to a text file using PHP.

I then use PHP to load and reverse the contents of that text file (newest news first) and display (echo) it on the index page. The only problem is, wherever there is a single quote, a backslash is being added right before it. Code:

View 1 Replies View Related

ADVERTISEMENT