Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Breaking Out Of Quotes


I know I can use stuff like in front of " so that it can't break out of a "" and start doing bad things, but it seems there are other situations where, E.G., if the string is hex for " then it has the same effect, and stuff like that, and it gets tricky escaping it all, so I'm wandering, is there some kind of option I can enable or extension I can install that just simply prevents objects/variables/arrays from breaking out of single/double quotes and also for mysql queries?

And also for html so E.G. echo"<img src='$asdf'>"; can't be exploited to do other things? I don't care if it isn't free as long as it works good and isn't to expensive..




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Escaping Single Quotes, Double Quotes, And Semicolons With STR_REPLACE()
i have this error code unexpected T STRING on this line:

str_replace(addslashes('onmouseover="showImg('name', 'tabla_novedades2', 's_asc.png', 'img1');"'), addslashes('onmouseover="showImg('name', 'tabla_novedades2', 's_desc.png', 'img1');"'), $td_name);

i tried escaping slashes with the addslashes function but obviously this did not work
there is a ";" in the string so i know that is causing the error

I am replacing this string:
'onmouseover="showImg('name', 'tabla_novedades2', 's_asc.png', 'img1');"

with this string:
'onmouseover="showImg('name', 'tabla_novedades2', 's_desc.png', 'img1');"

how do I do this with no errors with the str_replace function??

Stripping Double Quotes And Replacing With Single Quotes
I have a problem I had trouble finding any existing threads on in the forum.

I have tried learning more about str_replace() but have had trouble with implimentation.

Here is what is happening. I am adding text to a variable called $content that looks like this:

Hi everyone. This is text I made up. I think it was Larry that said, "Love is a battlefield". But I think it was Benitar.

Now I want to replace those " " in there with ' ' (single quotes.)

Practical Reason For Single Quotes Vs Double Quotes
I've always wondered why - or even if there's a difference - for using double quotes vs single quotes in php.

My code typically ends up with a mish-mash of both - sometimes I'll use:

$tomorMonth = date('n', $tomorrow); on one line, and then,
$arrMonth = $_POST['arrive_month']; on another line (or lines)

Both seem to work okay - I don't seem to be throwing any errors - but my question here lies in the interest of getting the "best practices" usage straight so I can start implementing single or doubles as appropriate.

So... when SHOULD someone use singles over doubles ... or does it make any difference to php at all?

Single Quotes And Double Quotes Showing As ? On Web Page
I have an issue with quotes showing as question marks on my webpage. I am sure its a UTF-8 related issue, but some of the facts surrounding the issue confuse me. The database is MySQL and stores the text as UTF-8. The PHP script simply takes the data from the database to a string: $desc = $info['description'];

And the text itself, is in a HTML string in the database as:

<P class=MsoNormal style=MARGIN: 0in 0in 0pt>The Golfers will enjoy their favorite sport on the Golf course only 5 min drive from “The Vineyards”.</P>

I am pretty sure that the original source was MS Word, and that the double quotes, in this example, are the special quotes from Word and not the ASCII quotes. When the webpage displays, it displays with the Unicode encoding. So, database is UTF-8, assignment in PHP is simple assignment without any form of stripping, tag removal etc.  And encoding on webpage is Unicode.  So can anyone suggest why they arent being displayed?

In the above example, the latter part of the text shows as ?The Vineyards?
It seems to apply to double quotes for sure, but also to some single quotes, as I have other text that displays as it?s instead of it's.

Double Quotes & Single Quotes
I have a web page with four input boxes. If a user types in text with either single or double quotes the insert fails.

I have looked into solutions and there seems to be some disagreement on the best method.

Some people say turn on magic quotes while others say not to, or use addslashes and stripslashes and again some say not to.

What about an mssql version of mysql_real_escape_string and mysql_escape_string??

What is the correct method? How do I overcome?

Single Quotes, Double Quotes And "undefined Index"
I am trying to write clean code but keep having trouble deciding
when to quote an array index and when not to.

sometimes when I quote an array index inside of double quotes I
get an error about enased whitespace (to my best memory)

AT other times I get an undefined index notice as below:

Notice: Undefined index: last_reminder_id in...

the 2nd line (which wraps to the 3rd in this posting
is the one listed in the error message:

$sql = "SELECT * from notes
where recall_date &#390;' and recall_date <= '$now' and id >
'$_SESSION[last_reminder_id]'";

what is the correct syntax and/or can anyone point me at a
reference that will explain this ?

Breaking Strings?
I have a string (actually 100's of these, but lets take one):

$string ="TI: Some journal title AU: SomeAuthor,-S; Smith,-A; Jones,-B SO: SomeSource. 2002 Jan 9; 287(2): 188; discussion 189-90 JN: Some Journal Title";

This needs to be turned into an array:

$entry = array(
'Some Item Title',
'SomeAuthor,-S; Smith,-A; Jones,-B',
'SomeSource. 2002 Jan 9; 287(2): 188; discussion 189-90',
'Some Journal Title');

As you can see, each array item should be defined by what comes after either/all of the following: 'TI:' 'AU:' 'SO:' 'JN:'

So, I need to be able to create a pattern that can look through the string and return everything in between TI: and AU:, then AU: and SO, etc.

for example:

eregi(???, $string, $entry);

I'm fairly new to this and can't seem to figure out the regex I need for the pattern. Is this even the way to go about it?

Breaking Out Of An Iframe
I cannot figure this one out. My script is being displayed in an iframe (a wiki page) and I have one option won't give me the correct results unless the page is displayed in either

a) new tab in NS browser
b) new browser instance.

The option in question is used to print forms, and I use the browser Print Preview for the page setup. It's all pretty useless if I have the page and iframe content in my preview.

I thought using header() would do the trick.

Breaking A Page Down.
What is the best solution to break down a php page into certain section using MySql, For example i'm looking at designing a page that reffers to a MySQL database that contains the html code for the navigation. So that in future if the navigation changes I'll only need to changed the html code in the database and all the pages will be sorted. I'm also looking at doing the same for the information on the footer of the page, with teh contact details.

Breaking Up Querys
I have a page that updates a table every workday. (these are standard updates, like if someone has moved, or has a different phone number or something.)  It is too big of a query to run the entire table all at once, so it is split out. 

The split is grouped by the first letter of a first name field.  Right now it is broken up into 5 parts, and each part has a group of letters (i.e. "a" to "d" is one group, "e" to "k" is the next, and so on.  As you can see, these do not have an even number of letters, but that is because some letters have a lot more entries, and need to be in smaller groups.) 

The reason it is split out into 5 groups is that I can run one group on each workday (Monday through Friday), and I can have the PHP check what day of the week it is.  (I use a case statement, the first case is for Monday, the second is for Tuesday, etc.) Code:

Breaking A Loop.
I have one going through rows of a sql database until it matches some data with user input. I need to put a break command in there but can't seem to find out how to achieve this.

Breaking Rows
I am using a while statement to pull results from my database. Now if I have like 40 results how would I make it break into rows.

So instead of;

result result result result result result result result result result result result result result result result result result

I want;

result result result result result
result result result result result
result result result result result
result result result result result

XML Parser Breaking Up URLs
I'm having a problem parsing an xml file in which one of an elements character data is a url which contains multiple "&" characters. For some reason the parser breaks up the data into multiple pieces. For instance, when I call this function(abbreviated):

function characterDataHandler ($parser, $data)
{
global $element;
global $url;
if ($element == "URL") {
$url = $data;
echo "url=".$url."<br>";
}
}

I get some output like this:


url=http://www.somewebsite.com/index.jsp?s=af

url=&

url=filter=1

url=&

url=show=all


Do urls with querystrings have to be handled differently then regular character data?

For Loops Breaking At A Certain Multiple
Can someone help me out with writing a script that will make will loop 500 times, but at every 4th multiple, it will insert a peice of code?

I tried all day to get this, and so far, nothing has worked.

Characters Breaking My Query
Im using encrypted data to store cc info. The PHP code encrypts and sends the result to the database. the problem is that the encrypted string contains lots of characters that will break my sql query. I can do a replace but there are lots of characters.

for example, a character will look like this:

g%$^'GDF$%^//"@#$%/||''$#"/|#dfsa.

how can I put this information in a different format... and then retrieve the data to decrypt the string?

Not Breaking Loop In Function
I get this error: <b>Fatal error</b>: Cannot break/continue 1 levels in <b>file.php</b> on line <b>128</b><br>

This happens when I call a function. In the function there is a break; This is cause the break is in a function and not in the loop. But it gets called inside the loop. Is there a fix for this?

E-Mail Not Breaking Lines
I'm sending an e-mail via a contact form, but somehow the lines aren't breaking in the text, it always looks like this:

lorem ipsum

dolor

sit

amet

lorem


Which is of course not readable at all. What am I doing wrong here? I'm using a few security checks and such for cleaning the field up; $text = trim($text);
...
$text = stripslashes(strip_tags($text));
...
$text = mysql_real_escape_string($text);
.....

#and then the part where it's included in the message:
$message .= "Nachricht: {$text} ";

Can any of those be causing the display problem?

Script Breaking On Mysql_result
I was trying to figure out why one of my scripts was failing and by using an "or die" statement for the SQL narrowed it down to this bit of code:

$md5 = md5_file("swf/" . basename($jpg_link));
$dupe = mysql_result(mysql_query("select count(gId) from games where gSwfFile='$md5.swf"), 0);
if(!empty($dupe))
{
continue;
}

This is giving the following error - "Warning: mysql_result(): supplied argument is not a valid MySQL result resource"

The thing is, I've checked that SQL query by running other values in place of $md5 through it and it appears to be fine. 

select count(gId) from games where gSwfFile='Flat War july 30th 2007.swf';
Any ideas?

Header Function - Breaking Out Of A Frame
I can create a plain htm link and have the new page break out of frames. a href='page.html' target='_top' Can this be done with a Header redirect in php?

Breaking Backwards Compatibility - Good Or Bad?
If you have any PHP scripts which will not work in the current releases
due to breaks in backwards compatibility then take a look at
http://www.tonymarston.net/php-mysq...everything.html and see if
you agree with my opinion or not.

Breaking Survey Into Seperate Parts?
I have a very long survey form with 4 different sections. Is there anyway with php to split this form into 4 popup windows so the person can click on the section they wish to fill out and when they are done, go back to the host survey form and continue on? I know there must be a way to do it, i'm just at a loss as to how i would pass the variables off? Cookies perhaps?

Breaking Up A Comma Seperated List
i have a list seperated by commas: 1. 3. 5. 7. 9 actually is a varible

$members ="1, 3, 5, 7, 9"; what would be the best way to break that up to insert the values into a table in a loop.

Breaking Up Text For Multiple Pages
I was recently put in charge of heading up my company's website, and
while I have a lot of experience on the design side of things, I'm
still very new to the programming side. When I started, the website had
just gotten a revision, but the site was an utter mess, so I've been
trying to fix it up. As I've gone along, I've learned some aspects of
PHP, but my knowledge is still very limited.

Here is the problem I'm trying to fix. A backend is used to enter
information into our MySQL database, and then a page template pulls it
out to make the page. For our reviews, the PHP coding currently breaks
up the review's text so that it can be places across multiple pages.
The problem is, the way the text breaking was set up, the end of one
page and the beginning of the next are totally chaotic, with breaks
often coming mid-sentence.

Here is what I'd love: other coding automatically puts an HTML break at
the end of paragraphs, and then another in the space between one
paragraph and the next. I'd love to have the code search for when those
double breaks come up, and then break up the text after, say, every
sixth pair of HTML breaks. I'd also like the option to break the text
myself by putting in some sort of text code in the original text. At
this point, though, anything that can make the breaks more elegant
would be a huge improvement.

I really appreciate any help anybody can give me in this one. Please
remember that I know very little of PHP, and I'm not much of a
programmer anyhow, so things that you may take for granted that people
would understand about PHP, I might not know.

I tried to pull out what I thought was the current coding for the text
break. Here it is. I'd also like to get rid of the part1/part2 factor.
Before, they had the text breaking to help in fitting into the layout
around an image, but I've fixed that so I no longer need the break. So,
that portion no longer needs to be a factor.

if ($page == ""){
$page = 1;
}
$no_letters = strlen($Game_Full_Story);
$times = ($no_letters / 3800) +1;
$Game_Full_Story = wordwrap($Game_Full_Story,3800,"*#^");
$Game_Full_Story = explode ("*#^", $Game_Full_Story);
$pages = array();
for ($i=0; $i<$times ; $i++){
$part[$i] = $Game_Full_Story[$i];
if ($i != 0){
array_push($pages, $i);
}
}
$page = $page-1;
$story = $part[$page];
if (strlen($story) < 460){
$parts1 = $story;
}else{
$story = wordwrap($story,460,"*#^");
$story = explode ("*#^", $story);
$parts1 = $story[0];
$count = count($story);
$parts2="";
for ($i=1; $i<$count; $i++){
$parts2 .=$story[$i];
$parts2 .=" ";
}
}

Breaking Up A String Into Individual Words
I have a text box that I will use to search a database. I would like
to use it so that it will not use a whole string (ie. 'red striped
top') but instead break it up into individual words (ie. 'red',
'striped', 'top') and maybe put it into and array. I will then use the
words in the array to search the database.

How do I break a string up this way?

Also, is this the most common way of creating a means of searching a
database?

Breaking Up The Query String Dynamicly?
using $Get_string = $_SERVER['QUERY_STRING']; to receive a query string such as
month=may&$day=15&year=2006

so that $Get_string = "month=may&$day=15&year=2006"

can I separate the values and turn them into variables? (like a normally would with a url get)

$month = "may"
$day= "15" etc

it would be great to just do $_GET on the url but I'm sending the string as a variable to another script... so i can't just go the easy route.

Breaking The BACK Button (Refresh Problem)
I have a php page which serves up multiple pages based on how the user
interacts with it - there are links on the first page that will reload (from
the same php file) a new page with form fields and submit buttons, and when
a user posts from that new page (or cancels), then the same php file is
again loaded, detecting how the user responded and generating the
appropriate html for whatever should be none next. All very typical.

What I want to know is, is there a way so that once a user has posted from
some submit button from one page (we'll say he Cancel's from a page that had
a form Cancel button so he returns to the original non-form default page
generated from the php file), can it be made so if the user then "refreshes"
the new page (hits the Refresh or Reload browser button) he does NOT get the
browser's "The page cannot be refreshed without resending the information.
Click Retry to send the information again, or click Cancel to return to the
page that you were trying to view." dialog? In other words, what I'd like is
a way to have the browser think that there was no posting done (even though
there was) once I've generated this certain 'home' page with my php code, so
that user ReLoad's of the page won't get this warning.

This is probably related also to problems I've had with "breaking the BACK
button" on sequences of php pages: if the user BACK's up to a page that was
generated by a post, it may not even be possible to regenerate the original
page.

Return Data Breaking Input Field
My return data is: (I have nothing to do with how the og person choose to input this)

<font color="#800080">CASE</font>

and I am setting the value of a input text form field equal to that return

$input      = "<input type="text" name="queOpt". $i ."" value="". $this->_queArr[$i] ."" />";

im lost on how to fix this. addslashes doesnt make sense  - maybe it is the double quote thing

Quotes Or No Quotes?
I am not getting a false return when i need it. Which one of these is correct?


return false;

return 'false';

return "false";

Quotes
<input type=text value="She said "It was cool" today">
<input type=text value='She said 'It was cool' today'>

Spot the problem?

Whats the best way around it, because when people are adding quotes in these boxes and its being inserted into a database then pulled back out for inclusion in a text field, its causing issues where as the outputted value is

She Said

Can't Escape Quotes
I'm having a problem trying to display a value which has quote marks. e.g.

Using Single Quotes
Is it a bad coding to use single quotes ' ' instead of " ??

Stripslashes Vs Quotes
Hmm, I can apply stripslashes() to a string, causing it to remove slashes
near quotes (") but how can I change this quotes to appropriate HTML
quotes like &quot;?

Magic Quotes
I now have my site hosted on has the magic quotes enabled. Is there an easy way to tunr it off? Or do I have to go into the configuration and change it permantly? The set_magic_quotes_runtime(0) doesn't seem to have much effect.

Please Help In Preg_replace Quotes...
I have this peace of code which isn't woking as I would like it to work.

$tekst = preg_replace('/"/', '&quot;', $tekst);

In my forms, I would like to change " to &quot; but this line is actualy
"stripnig" text that it looks (or "cames to mysql db) like:

Lorem ipsum "

instead of

Lorem ipsum "dolor sit amet" ...

Daily Quotes
I am trying to write a script in php that display quotes on a daily basic. I have the db tables setup I also added 3 quotes to the table to test the script. The script is working except the quotes are displayed randomly instead of daily. Whenever I refresh my browser another quote appears.

I would like to have these quotes displayed on a daily basic.(IE: November 19, 2003 quote should only display today whereas November 20, 2003 quote will display at 12:00am) although, November 19, 2004 the same quote for 2003 should display (in case I haven't updated the latest quotes for the following year(s) which requires an if / else statement. What am I doing wrong or what didn't I do right? I am no good at the date() and time() function. PHP Code:

Single Quotes
I'm having trouble with single quotes in a string being inserted int o a textbox like this:-

<? echo "<INPUT TYPE='TEXT' NAME='vsign' VALUE='$vsign'>";?>

Now If $vsign="text with sing'le quote";

this displays :- text with sing in the text area. PHP appears to read the quote as the end of $vsign. I've tried escapes but they dont seem to work.

Escaping Quotes
I developed some code to insert data into an access database using odbc commands, and my code is below. PHP Code:

Problem With Quotes
I'm writing a PHP line to the foot of a file using another language. my
problem is I'm not sure how to write it so that the quotes (both single
and double) are corret for PHP to process.

The language I'm writing the PHP line with uses single quotes for a print
statement.

Therefore the line I want to write is (reducing to a single array
element to simplify):

$myArray = ( "Quote" ="It's time, "he said."" );

As you can see the quotes are complex already - but this line must be
written from another language enclosed in single quotes as:

print '$myArray = ( "Quote" ="It's time, "he said."" );'

So - my question is - how on earth do I escape such a thing?

Escaping Quotes
I'm trying to remove a directory in UNIX through php called: newton's_cradle Yes, the dir name actually has the escape character in it. At the UNIX prompt, I can use:

rm -Rf newton's_cradle

I escape the first backslash, and then escape the quote. Works fine. However in PHP it doesn't.

exec("rm -fR /path/to/dir/newton's_cradle");

neither does

exec("rm -fR /path/to/dir/newton's_cradle");

I'm sure I'm doing something wrong, overlooking the simple solution.

Magic Quotes
I'm just wondering what kind of benifits Magic Quotes provide and if they should be turned on or not and what aboult the gpc,runtime,and sybase?

Quotes In Textarea
buit this time I haven't found solution in some
manual...

problem: I would like to allow <a href="link"> tag, but I'm having
problems in hidden field when checking message:

situation:

(STAGE 1 = typing <a href="link">message</a>)
<form method="post">
<textarea name="message"></textarea>
</form>

(STAGE 2 = checking message, my wish)
$message = $_POST['message']
<p>Is following correct?<p>
<p>typing <a href="link">message</a></p>
<form method="post">
<input type="hidden" name="message" value="message">
</form>

(STAGE 2 = checking message, my problem) <----!
$message = $_POST['message']
<p>Is following correct?<p>
<p>typing <a href="link">message</a></p>
<form method="post">
<input type="hidden" name="message" value="typing <a
href="link">message</a>"> <----!
</form>

there it breaks... my $message became
"typing <a href="
insead of
typing <a href="link">message</a>

what to do?
one soulution came right now to my mind... but still have some
questions:
to create copy of $message and to place that copy to hidden holder and
later, just before inserting it to mysql db, to convert it back.... and
what will happen in mysqldb with "?

preg_replace " with ******...? hm, how to find """?
maybe preg_replace('/\?"/', '******', $tekst) ?

What Are Magic Quotes?
I've looked all over the place and I can't find anyting that explains what Magic Quotes are and what they have to do with anything.

Quotes From Db Into Textfield
i have a problem of wich i doubt it can be solved properly:
If i call a text from a (mySQL) database, and want to echo it into a
textfield (e.g. in a form) i experience the following problem (wich
makes sense, but wich i can't solve):

Imagine the following: ...

Quotes And Slashes
I've been trying to solve this but to no avail. I know there can be problems with quotes and slashes but I've not had this specific problem before. I have multiple blocks of text (html code) containing double quotes and html tags: Code:

Don't Use Magic Quotes?
How do I do a character like "..." ?I want to echo the double quotes (like in a href).

Magic Quotes
I know " and ' is considered magic quotes Are considered magic quotes?  If i turn magic quotes OFF, will still work?

Htaccess And Magic Quotes
Can anyone tell me what to write in the .htaccess file to turn magic quotes off for that directory> I've been told it's

php3_magic_quotes_gpc off

or

php_magic_quotes_gpc off

But this doesn't work. I get an internal server error. I want to do this as one php app like magic quotes off and another likes them on.

I do wish the
if (!get_magic_quotes_gpc())
{ do something}
else
{do something else}

Quotes And Add/stripslashes Problems
Alrighty, i'm sure this has a simple solutions, but here it goes: I have some data stored in a MySQL database, and it has quotes, and all kinds of PHP characters, so naturaly, I call addslashes before I put it in, but I use this data to match up to variables in my script. What I mean is, say there is the data PHP"var in a column, when I add slahses it comes to PHP"var, and that is how it's stored in the database. Now say i make a variable in a script like:

$var = "PHP"var";

thats the only way i can make it or it would'nt be the same because it would end the name at the virst quote and probably return a error. But this is where it gets messed up, because when i do my sql statment and say WHERE `column` = '$var' it will not match up because PHP escapes the backslash to read the quote, but the backslash is stored in the actual data in the MySQL table. Any thoughts on this problem would be grealy appriciated.

Using Double Quotes In CSV Files?
I've got a CSV file in which I need to use double quotes and import into MySQL.
However, I've tried using a in front of each quote. I've tried using the HTML code. They doesn't work (and it's not something I want to mess with during data entry).

The HTML code gives a parse error.


Copyright © 2005-08 www.BigResource.com, All rights reserved