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


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Regex For Matching A Quoted String With Possible Escape Characters


I seek a regular expression, pcre or ereg (it doesn't matter), which,
given a quoted string (e.g. "foo" => foo) will return the contained
text, but that will accommodate escaped quote characters within the
string (e.g. "foo"bar" => foo"bar).




View Complete Forum Thread with Replies

Related Forum Messages:
Escape Characters In A String
Is there a way to strip escape characters from a string?

I am trying to send a html email which includes hyperlinks. But this doesn't work as the quotes are preceded by a slash.

View Replies !
Difference Between Quoted And Not Quoted SQL Query
the difference between quoted and not quoted sql column names

$query = mysql_query("SELECT * FROM table WHERE row = '$row'");
$query = mysql_query("SELECT * FROM `table` WHERE `row` = '$row'");

View Replies !
Regex - Matching Local IPs
I'm just trying to get PHP to sniff out local users using preg_match; can anyone spot my error?

preg_match("/(192.168.(0-9){1,3}.(0-9){1,3})(10.(0-9){1,3}.(0-9){1,3}. (0-9){1,3})(172.(16-31).(0-9){1,3}.(0-9){1,3})/",$_SERVER['REMOTE_ADDR'])

View Replies !
Regex Not Matching Spaces.
I'm parsing a body of text for tags that use square brackets to identify themselves, like BBCode. These tags may contain alphanumeric characters, spaces, apostrophes, underscores, dashes, basic punctuation, and pipes. The closest that I've been able to come up with is:
PHP Code:

View Replies !
Regex For Matching Links
When looking to match text within <a> tags, I have this REGEX, bearing in mind that the input $tag is a single <a> tag on its own line;

preg_match("'hrefs*=s*(["'])([^"']+)(["'])'i",$tag,$link);
if(!$link[1])
preg_match("'hrefs*=s*(^s*)'i",$tag,$link);

Would this be OK or are there exceptions? I'm not too keen on having ["'], preferably it would find one either the " or ' characters and then find the matching end character rather than either/or at both sides. I've never been sure about using backreferences, couldn't get this code working, though if you look at it you can probably see what I want to do in light of the above...

preg_match("'hrefs*=s*(["'])([^1]+)([1])'i",$tag,$link);

Is that the correct way to use the backreferences? Putting some examples through my code and the output seems to be a bit flaky. I'm using similar REGEX with a preg_match_all to look for alt/title text within tags so hints about using backreferences.

View Replies !
Regex Pattern Matching
The pattern is required as:

"Item purchased: [text, can be many workds] (Item #[at least 10 digits
number])"

Here is an example:

"Item purchased: Intel Pentium IV 3G CPU (Item #23467893452)".

View Replies !
Regex Not Matching Spaces
The closest that I've been able to come up with is: Code:

$text=preg_replace_callback('/[([A-Za-z0-9¦'.-:underscore:]+)]/i' , "findLinks", $text);

this does not match spaces for some odd reason (the "." should match them, I think). I've added "s", "w", " ", and ":space:" to the regex (tried both before the A-Z and after the 0-9) but for whatever reason those spaces are not detected. Why? What must I do.

View Replies !
Matching LARGE Regex Strings?
I have a large HTML string that is multiple webpages attached to each other (one long string). Because the headers and things are the same (comments, navbar, sidebars), I would like to get rid of them since I know there are multiple copies (indexing, so multiple copies throws off data). Code:

View Replies !
Regex - Finding A Matching Text
On a page i have things like this:

<span id="ctl00_ctl00_content_PlayerAvatar_lblNickName">FIND THIS</span>

That is in the middle of tons of other stuff (its part of a webpage) and i want to find whatever is where "FINDTHIS" is on the page.

*ADDEDINFO*
To explain better, what i want the code to do, is search through the source for that span line, and set a variable such as $nickname = "FIND THIS";
*/ADDEDINFO*

I know im not explaining this very well, but its the best I can do. If you have any questions dont hesitate to ask.

View Replies !
Getting Rid Of Escape Characters.
i am sending the contents of an html text area with the name "message" using the mail functions like.

mail($email, $subject, $message, "From: someone@somewhere.com
Reply-To: someone@somewhere.com
X-Mailer: PHP/" . phpversion());

when the user gets the mail all apostrophies (') are escaped like ('). how do i prevent this?

View Replies !
Characters To Escape?
I am looking to make my own escaping system, although i don't know the major characters to escape? Is there any really bad characters that must at all times be escaped.

View Replies !
Escape The Xml?> Characters
This seems to cause a problem as PHP takes the?> to be the end of PHP script. I then get a load of PHP in my XML file that was created. Anyway to escape it?

<?php

include("DBConnection.php");

// open a file pointer to an RSS file
$fp = fopen ("rss.xml", "w");

// Now write the header information
fwrite ($fp, "<?xml version=&#391;.0'?><rss version=&#392;.0'><channel>”);

View Replies !
Why Is PHP Adding Escape Characters?
I'm making a simple preview function. first page is a text area exactly like the one used to post on this page. Page 2 is a preview. Well, on page 2, it's escaping all the escapable characters for no reason at all.

so i type:
hello, "person" what is up?

I get back this:
hello, "person" what is up?

View Replies !
How To Use Escape Characters (particularly #) With $_GET
I don't have a lot of experience using $_GET.

I need to know how to pass characters in using the $_GET method. The
character I'm having a problem with right now is '#', but I'm sure
there are others.

Could anyone give me a list of characters that need to be escaped
using $_GET, and then also how to use them?

Also, could you tell me if any characters simply are not allowed in a
get?

Example:

getData.php?type=edit&user=myName&item=Item#1

View Replies !
Php And Mysql Escape Characters
Everytime I want to enter to a textbox area "it's fun" (no quotes) I get an error.

"Problems with Query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's fun'"

I need to enter " it's fun" (no quotes) in order for MySql accept it.

Any work arounds on escape characters? How can I have mySQL just take "it's fun" just like that?

View Replies !
Escape Illegal Xml Characters
does anyone know of a good function to escape all illegal characters? I've been writing a bunch of string_replace functions for each of my files and it is getting pretty tedious and I don't know if I am even catching all the possible (or even likely) problems Code:

View Replies !
Stripos And Escape Characters
I got a problem and i'm stumped. I am using the strripos function to find the position of a string. For example, for finding this string:
Type</td><td valign="top" align=left>"

the following command worked great:
strripos($mystring, "Type</td><td valign="top" align=left">

All I had to do was add the backslashes () before the quatation marks (").

But with this string:
Poster</td><td align="left" valign="top"><img src="

No matter what I try, it doesn't find it, although I'm sure its part of the string.  This command craps out:
strripos($mystring, "Poster</td><td align="left"")

But this command works:
strripos($mystring, "Poster</td><td")

I narrowed it down to the " a" in the word "align" giving me the problems. What am I doing wrong?

View Replies !
Dealing With Escape Characters
I am trying to put the following text into my DB but mySQL keeps rejecting it as the character is invalid. The character is ; which has obvious problems. I have tried escaping it with ; but doesn't work either. Any ideas?

View Replies !
Escape Characters Not Escaping
i have a form which submits its data to contact.php. if the form has not been filled out properly, an error message is generated and sent to sent.php to display information for the user regarding the problems with the form. the problem lies with the link to return to the form that is generated by sent.php.

this is the relevant section of contact.php. all of the error variables are defined in the full code: ...

View Replies !
Escape Sequence Characters Problems?
Does anyone know why escape sequence chars. dont work? eg.1

<?php echo ("HelloWorldn");// the n doesnt work ?>

when i try: eg2

<?php echo "HelloWorld<br>";// the newline works with the html <br> tag ?>

also:eg3

<?php echo ("HelloWorld<br>n");// this works too ?>

I am finding it very funny, is it a bug in the PHP or what?
Also why in eg2, is it that an html tag is working in PHP statement when the n or t etc. should be working. And what bout eg3, that seems even more odd.?

View Replies !
Function To Escape Illegal Characters
I have a query that I am populating a drop-down menu with. I need to escape illegal characters, but I'd like to separate it out from the page. Code:

View Replies !
Escape Characters In Text Variables
My problem is that I have an admin page with a form that passes text to a mysql db.

Anytime I put a ' in the text the script returns an error, and I have to escape the character before it works.

here's the code...

$maintextdata = $_POST["editmaintext"];

$pagename = $_POST["replacedata"];

echo $pagename;

$sqlmaintext = "UPDATE menu SET maintext = '$maintextdata' WHERE linktext = '$pagename' LIMIT 1";

I assumed it had something to do with my syntax, again, but I've tried different ways with no success, and some worse scenarios where i had to escape " and , aswell as '.

nearly forgot, the script works fine on another server, could it be a problem with my current server's php version? which is 4.3.11-1.fc2.3.legacy, as far as i know.

View Replies !
Escape Characters In Echo Statement
Why doesn't the following line workin in php?

echo "$_REQUEST[/'checkAllDefault/']";

I get the error message:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in

View Replies !
ODBC Escape Special Characters
I'm currently trying to figure out how to use ODBC with PHP4 and PHP5 to connect with an Oracle database. The problem that I'm having that I can't seem to find any documenation is how to properly escape special characters in the SQL statements used in the ODBC such as single quotes in the strings. I would imagine there would be something similar to MySQL's mysql_real_escape_string but could not find anything in the docmentation. I thought odbc_prepare handled it for the developers but I guess I was wrong.

For example,
$sql = "INSERT into MyTable (FNAME, LNAME, IP, SN) VALUES ($fname, $lname, $ip, $sn);
$stmt = odbc_prepare($dbh, $sql);
$res = odbc_execute($stmt);

Does ayone know of some odbc function that handles all the escaping of the special characters?

View Replies !
Escape Characters Added To Form Data
Some characters entered in the text fields of a form get an escape
character. What is the reason? How can I prevent/remove this?

Here is an example:
<form action=hello.php method=post>
<input type=text value=firstname>
</form>

If the user enters:
O'Hara

And I have the following file hello.php:
<? echo $_POST['firstname']; ?>

The output is


View Replies !
Regexp: Not Matching A Sequence Of Characters
and this may be a rather dumb
question, but so far I haven't found the answer in any tutorial or reference
yet...

If I have f.i. the string "The {{{{power of {{{{regular expressions}}}}
comes from}}}} the ability to include alternatives and repetitions in the
pattern." from which I want to extract chunks starting with "{{{{" and
ending with "}}}}".

When I use "/{{4}((?s).*?)}{4}/" as the pattern, it matches "{{{{power of
{{{{regular expressions}}}}".

What I want is for it to match "{{{{regular expressions}}}}", so somehow I
should be able to avoid having "{{{{" contained in the subpattern.
Exclusion, afaik, only works with character classes and not with with
sequences of characters.
I could make the the subpattern exclude the "{" character as in
"/{{4}((?s)[^{]*?)}{4}/", but this does not satify my needs because I
want to avoid the occurence of having 4 accolades, no more no less...

so, how would I have to write the pattern to exclude a sequence of specific
characters, rather than a character class?

View Replies !
Regexp - Matching Text Not Containing Certain Count Of Certain Characters
I'm trying to build a regular expression (POSIX extended). One part of it has to match any text not containing a slash except standalone two dots (..), but I can't find the way to say something like "match any count of any characters except string ..".

For example, it should match
...anything..
aaa..
....

but must not match
anything/containing/a/slash
...

View Replies !
Escape A String
If a string contains characters -- and ', how do I escape the string so that I can compare this string to others or store it in database?

View Replies !
How To Escape String For Preg_match?
I have a string equal to 'www/' that I want to use in a preg_match. Php
keeps giving me the warning:

Warning: preg_match(): Unknown modifier '/'

How can I escape the string so the / in www/ is not interpreted in the
preg_match ?

View Replies !
Escape Tags In A String
I have a complete file in a single-line string. Now this string also contains <? and ?> or other script-tags. Of course if I "print" or "echo" the string the php won't be interpreted. But that is exactely what I want. I want scripts like PHP to be executed when I print that string e.g. in a template. Instead it shows something like this:

"
This is the content of my file <? echo "__FILE__"; ?> which I want to execute scripts.
"

Anyone know how to have them PHP-Tags be processed?

View Replies !
Oracle Escape String
When using PHP and MySQL, I know there is a nifty function called mysql_escape_string, to escape whatever you might need to put into your SQL. Now we're coverting from MySQL to Oracle. I'm trying to figure out how to create SQL statments with propertlly escaped strings. There doesn't appear to be an oci_escape_string function. I'm using PHP5 and Oracle 10g on RHEL 4.

View Replies !
Real Escape String
How can i add a escape string to this php mysql query.

mysql_query('insert into times (code, date, time, duration) values ("'.$course_code.'","'.$date_inSQL.'","'.$time_inSQL.'","'.$duration.'" )');

View Replies !
Mysql Escape String Permissions
I am using mysql_real_escape_string() for my $_POST variables but I get this error

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'themiss2'@'localhost' (using password: NO) in /home/themiss2/public_html/writing/account_process.php on line 5

I'm not sure how to fix it.

ps. this is all based out of cPanel and phpMyAdmin for web and database organization (if that helps withthe problem)

View Replies !
Escape Character In Query String
use the urlencode function to "escape" the special characters. After, use urldecode to get the string back to normal.

View Replies !
Although English Characters Appear Correctly Into The String, The Greek Characters Are All Replayed By '?'.
I am using php 5.2.2. I implement a web site that invokes a java web service (using nusoap.php).

The web service queries a table from an sql server 2000 database and returns a string with the records returned. The problem is that although english characters appear correctly into the string, the greek characters are all replayed by '?'.

The reason must be that the web service returns multibyte charecters (greek characters) and php cannot read them.


View Replies !
Mysql Real Escape String() In Conditional Statements
I created the following bit of code that allows me to pass a MySQL conditional statement to a function.

I am trying to figure out where and how would I go about incorporating the mysql_real_escape_string() function?

Is there a way to call the mysql_real_escape_string() in the function itself? Code:

View Replies !
Multiple String Matching
I have a string of around 500 characters(alphabets) and I have a 3 arrays storing the position "start, end and type" for that string. i am trying to do is to match these position to the string and highlight those positions on the web page.

For example: string- ABCDREGYRIWJEKSALOPRHDAGRTPRTDBRTWASERFSDHSJHDS

start_pos=5
end_pos=10
type=helix breaker

start_pos=12
end_pos=18
type=unusual

so what I am trying to do is to match the pos and type to the string and in the output(webpage), trying to highlight the positions, may be drawing a rectangular box around the matched positions.and positions may overlap within each other. I am tying to use some of the functions for the string matching but unable to do for multiple matches.

View Replies !
Regex For Repeating Characters
I have a form for collecting user input. One user decides to type in:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Doing this messes up my page because it stretches the page too far, and it doesn't wrap.

Is it possible to use regex for detecting such repeating characters?

View Replies !
Regex :: Only Characters And Numbers
How do I only allow these characters: _, ,a-zA-z0-9 . tried using this code, but it didn't work. PHP Code:

if (!empty($user) && !eregi("[ _a-zA-Z0-9]", $user))
  echo "Bad Username.<br />"; .

View Replies !
Basic Regex Key Characters
I have been looking around the web for a good list of the basic regex key characters / commands, not just examples.

ie. w = word
.. = any character
+ = one or more
etc. etc.etc

View Replies !
Regex Accented Characters
I've been looking for a good way to have a regex check for a name allowing also for accented letters like in ....

View Replies !
How To Search Strings Escaped By Mysql Real Escape String()?
I am currently developing an article script and there are Titles and Contents. To prevent sql injection, people say we must use mysql_real_escape_string().

So let's say if there is a Title that says "My Friend's best friend", if I look into the MySQL table record, the text will be saved as "My Friend's best friend", where the apostrophe is escaped. Code:

View Replies !
Matching User Input String
I have a table with a column whose values contain regular expressions. I want to select the row(s) from this table whose regular expressions match the user input. I know how to use REGEXP to match a regular expression against values stored in a table, but I need to do the opposite.

I was really hoping this was possible within MySQL. The alternative I have at moment is reading ALL regular expressions (into my PHP script) and looping through them, testing as I go but this doesn't seem ideal.

View Replies !
Regex To Strip Special Characters
Does any one know of a regex to strip special characters and to return the first three words? I have deleted multiple spaces using:

$string = str_replace(' ',' ',str_replace($special,'',$string));

But, I'm not sure how to remove special characters besides doing this

$special = array('/','!','&','*'); etc..

Special characters are all characters not including letters or numbers. Also, I'm trying to return the first three words after this operation, which should basically contain just all words, since I've already removed the spaces.

View Replies !
Replace All Characters In String Except Keyboard Characters
I've been trying to figure this one out for a few hours and I'm not making much headway. Hoping someone here knows the quick solution...

I'd like to replace all characters in a string except for the set of keyboard characters. I figure this can probably be done with a preg_replace and some regex, but I'm afraid I need to bone up on my regex some...

View Replies !
Regex - Alphanumeric Characters Along With Underscore And Space
I would like to know the regex for the following: input text can contain alphanumeric characters along with underscore and space for example: "this is user_name"
i used the following:

[php]/^[a-zA-Z0-9]+$/[/php]

this works but not perfectly because when the only space bar is pressed it takes the value, i want to prevent this, space should be @ the beginning, what will be the regex for this?

View Replies !
Matching String To String
Is there a way to search a string so that if there is a match it simply returns true? I have tried many functions and they seem to not work. What i am trying to do is if i have one string, say a url (e.g. http://www.games.com), and another string (e.g. games), how do i compare one to the other whether it is in the first string?

And another thing, is there any way of finding the third occurence of a certain character in a string, something like the strchr() function?

View Replies !
Regex Matching 3 "-"'s
I thought I had a regular expression problem but I located the problem and its with the strtok, not my regex in above code-- I need to use strtok on a variable I have and break it on a "---", three dashes in a row, however, it seems to break on the last "-" in the string, even if it is only one dash.

$val1 = '---Invalid E-mail.'
$tok = strtok($val1,"---");
echo $tok;// prints -> Invalid E

it "should" be a emtpy variable.

I discovered a quick hack to fix this but I would like not to have to use this method. I have to pad the $val1 var with anything infront of the --- and it works right. As long as the "---" is not the first three characters in the variable it works right. However, I would like this to be able to work with a variable having "---" as the first three chars.. Any ideas?

View Replies !
Manipulate A String Using Regex
I wish to manipulate a string using regex. the php manual says i can use Perl compatible regex, but it doesn't seem to work. Basically i want to remove all whitespace (space, tabs, carriage returns etc) from a line

in Perl $line =~ s/s//;
in PHP $line = ereg_replace("s", "", $line);
except the PHP code removes all "s" and not any whitespace. Any ideas anyone?

View Replies !
REGEX String To Get Uptime?
I was wondering if anyone had a REGEX string (for PHP) that can get the uptime out of the *nix "uptime" command?

View Replies !
REGEX Change A String
I have 2 issues concerning regex:

1) change a string of:
number
umber
umber to number/number/number

for example:
2 to 2/0
312 to 3/1/2

2) change a string of:
numbers to digit/digit/digit

for example:
321 to 3/2/1
18 to 1/8

View Replies !
Regex For Query String
I'm creating an email marketting manager for work and we want to be able to track links in from the email so I want to find links in the plain Text and HTML parts of an email and append ?m=emailID&l=linkid but preferably not add them on if they're already there and add &m=emailID&l=linkid if there is already a query string on the link. Originally when I thought about it it seemed simple, but now thinking about the smaller details it seems much more difficult.

View Replies !

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