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.





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 Complete Forum Thread with Replies

Related Forum Messages:
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 !
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 !
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 !
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 !
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 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 !
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 !
String Indexing And Preg_match
Quick-Fix: Can preg_match_all return the indexes of where it matched the
string?

More Detail: Read carefully: I'd like to seperate a string's parts into two
(2) arrays which can be subdivide themselves. Then modify them and glue
them back together. I will refer to the two arrays as highlight and
remnants. The method I'm using to glue the string together correctly is to
store the string indexes (positions) of both the highlight and remnants
parts of the string before sorting the text into arrays.

ASCII Art Diagram (Mono-space text only):

Original
|
/
/
/
A B
/ /
/ /
AA AB BA BB

HTML entities like example:

Original:

The <html> rain </html> *in* Spain %d %s foo.

Split:

A - Highlight B - Remnants
--------------------------------------
The | <html>
rain | </html>
*in* Spain %d %s foo. |

Glued:

The &lt;html&gt; rain &lt;/html&gt; *in* Spain %d %s foo.

Separation Code:

$finds = array();
$remnants = array();
foreach ($src_array as $src) {
preg_match_all($pattern, $src, $tmp);
$finds = array_merge($finds, $tmp[1]);
$remnants = array_merge($remnants, preg_split($pattern, $src));
}
return array($finds, $remnants);

I'd like to know: what would be the best way to index text directly in the
separation process - to avoid duplicates being miss-indexed?

For example the following function content is bogus because it can't
distinguish which space character (' ') came first:

$pos = 0;
$l_size = 0;
$list = array();
foreach($needles as $needle) {
$pos = strpos($haystack, $needle, $pos+$l_size);
array_push($list, array(
"pos" => $pos,
"raw" => $needle,
"enc" => $needle));
$l_size = strlen($needle);
}
return $list;

View Replies !
Preg_match Exclude String Within Subpattern
I have a simple pattern that captures an anchor tag:

(<a.*?</a>)

It works great. I would now like to modify this to EXCLUDE occasional
opening and closing bold tags (<b></b>) around the text.

For example:

<a href="http://www.example.com><b>Example</b></a>

to return

<a href="http://www.example.com>Example</a>

How can this be accomplished?

View Replies !
Preg_match Find All Instances In A String
Im having trouble with preg_match_all. Im trying to make preg find all instances of test in a string, and then print out how many it found with a for loop. The problem is that only three test's are printet out. There are six in total. Below is the script :

<?

$text1 = "Test 1, test 2, test 3, test 4, test 5, test 6";
for ($t=0; $t<count($text1); $t++) {
  preg_match_all("/test/i", $text1, $match1);
  print "<br>".$match1[0][$t];
}
echo "<hr>";

?>

What am I doing wrong ?

View Replies !
Preg_match And Store Resulting String ...
i want to go through a file and find every occurance of a certain start tag, then put the contents following that indicator into a string up to the end tag. eg storing a list of all links on a web page. i can use preg_match to find the start tag but then am a bit stumped after that .

View Replies !
String Parsing.. Preg_match Problem?
I need some help parsing some text and turning it into some array values... Basically I will have some text like this:

CRITICAL 3-501.16(A)* PHF Hot Holding->140°F

Or like this:

5-501.17 Receptacle in women's toilet room coveredCRITICAL 3-302.11(A)(1)(a)* Separation-Raw & raw RTE

I need to parse out the data into an array... so for the second example, I need an array similar to this: Code:

View Replies !
Preg_match() Help How To Find Two Words In A String
I am just now diving into learning use regular expression and my head is spinning with all the articles I have been reading. I think what is must confusing is all the symbols that are used when creating a regular expression.

I have a database that has a field I entered some keywords. Now Im querying the database to search the keywords for words I passed through a link. Code:

View Replies !
Preg_match() Maximum String Length Reached
I am using PHP 5.2.0 on Apache 2.0 and trying to get preg_match() to scan a certain result string returned. However, it wouldn't match the regular expression with the data.

I verified the expression is valid in RegexBuddy. I also tested it again in PHP with a shorter string containing approximately the same kind of content and it worked fine.

After some very tedious testing I found that preg_match() simply stops working when the string is 100,055 chars in length. No errors, warnings, or notices. It just won't do the match if there are that many chars or more.

View Replies !
Preg_match - "Invalid String Format: $string";
I am getting form values like: aaaa bbbb ccccc xxxxxx I have been searching pre_match, eregi, regex to find a way to test the input form variables for 3 or more of the same characters. The code below does not work but may give you an idea of what I am looking for.

if (eregi("([a-z*]{3})", $string))
{
echo "Invalid string format: $string";
}

View Replies !
How To Parse Posted Variables To Do Preg_match And String Functions
I know how to parse posted variables to do preg_match and string functions. What I am wondering is if there is a way to parse global variables as a function. I am not too famialiar with functions per say, but I need to learn how to master them in order to finish my project. Here is a sample code php

$name = $_POST["name"];
$favorite = $_POST["favorite"];
$time = $_POST["time"];

echo ?>

What I am trying to do is striptags and preg_match the data to cleanse it. I know how to do that on a variable by variable basis, but I have a total of 31 variables that are user inputed. I hear that php5 has a cleanse function built in, but this is on php4..

View Replies !
Preg_match String Validation With Numbers,chars And Special Character
I need to validate an input form field.
It should contains only 0-9 digits, a-z A-Z characters and special character: .
I'm using preg_match("/[^a-zA-Z0-9.+ ]+$/",$element)but it doesn't work.

View Replies !
Title String - Warning: Preg_match() [function.preg-match]: Delimiter Must Not Be Alphanumeric Or Backslash
I have these vars:

$query = "cyan";
$line = "91. <a title="href=http://www.cyanstudio.com/><b>CYAN</b>STUDIO.COM </a><br>";

now I try to find if cyan is in the title string. So I do it like this:

preg_match('$query', $line, $matches);
but then I get this error:

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash

Any ideas?

View Replies !
Preg_match - Warning: Preg_match() [function.preg-match]: Delimiter Must Not Be Alphanumeric Or Backslash.
I am trying to match this this line
8f89c2f9-6939-4bff-b800-a6f46e2d0f24 it is a random number everypage load the full string is this MyToken=8f89c2f9-6939-4bff-b800-a6f46e2d0f24

I am connecting to the page with curl so the code is

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
$page = curl_exec($ch);
preg_match('MyToken=([0-9a-f-]*)', $page, $mytoken, PREG_OFFSET_CAPTURE, 3);
echo $mytoken;
echo $page;
curl_close($ch);

but it keeps giving me an error

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash.

View Replies !
Use Preg_match To Find Out If A String Begins With Either "http"
I try to use preg_match to find out if a string begins with either "http",
"/somethime" or "../something". In my php script I have the following line:

if (0 == preg_match("/^(http.+)|(/[a-z].+/)|(..[a-z]+)/i",$string)

But I get a:

Warning: Unknown modifier ')' in myscript.php at line nn

What's wrong with the pattern?

View Replies !
Help With Preg_match. Can't Use "" In String
I'm trying to find a string in a file but the problem is that the string contains back-slashes which cause an error.

For instance:
preg_match("/zend_extension_ts = "c:apache2htdocsphp-workshopp1example.txt"/", $this->contents);

But that causes the error
[24-Oct-2003 09:11:10] PHP Warning: Compilation failed: PCRE does not support L, l, N, P, p, U, u, or X at offset 32 in C:apache2htdocs est.php on line 107

I know why the error is happening but I want to know how I can work around it.

Can I maybe escape the slashes somehow, but so it still finds the string with slashes in?

View Replies !
Escape
<?php
echo ("Vladimir's brother said, "Ain't that a hoot?"");
?>

Vladimir's brother said, "Ain't that a hoot?"

Vladimir's brother said, "Ain't that a hoot?"

View Replies !
Escape <
I'm adding 3 strings and need to escape possible <? and <<< when they occur. I can't figure out a way to do it. This is the code joining the strings. If it comes across a <? in the results it does not add additional strings in the loop.

$Result = $Result . chr(intval($k/16)+48) . chr(intval(fmod($k, 16))+48);
for($m=0; $m<=$i-1; $m++)
{
$k=ord(substr($mpass,$m,1));
$k=$k+$LASTK+(27*$j);
settype($k, float);
$k= fmod($k, 256);
$LASTK=$k;
$Result = $Result . chr(intval($k/16)+48) . chr(intval(fmod($k, 16))+48)
$j++;
}

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

View Replies !
Escape Probem
I am having a little trouble copying PHP code into a file, here is an example of what I am trying to do...

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 !
Do I Need To Escape This Code?
After you all gave me some good advice recently, I'm back for more :o)

On my web site, I want to display a 'log out' icon with some text
underneath, ("Log out"), which, when clicked, will end a session.

This is the simple code I'm using for the icon:

<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=log_out">
<img border="0" src="images/logout.gif" width="74" height="74"><p
style="text-align: center">

This all works fine and, when clicked, the session is ended and the
user returns to my web site's home page.

Now's the complicated, (Well for me, anyway), bit; I only want to show
the 'log out' icon when the user is actually logged in.

So, I've been using isset to determine the session state:

<?php if (isset($_SESSION['user'])) {?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=log_out">
<img border="0" src="images/greenround.PNG" width="74" height="74"><p
style="text-align: center">
<?php }?>

View Replies !
Escape To Unicode?
I've begun dealing with PHP's XML functions (puttup!)

I shoudl say- php's DEFAULT XML functions, no extensions. Probably not
5.0. I don't care...

The POINt is, they choke on funny characters, even encoded funny
characters. You need to use the unicode. (change &ntilde; to ).

Whatevuh.

That's why, why- now ignore that part, because it will distract and
proably cause you to misconstrue the thrust of the question to follow:

Does PHP have a function that will escape all funny characters in a
string (encoded, unencoded, both, either...) to their unicode
equivilants?

In a string- ignore the XML parts of this question.

(I'm looking at pre-proscessing the data coming into forms that will
form the offending XML)

View Replies !
Escape Character & And #
Does anyone know the escape character for & and # like in :
Update GDO_INFO_ER set V_COMMENTAIRE='B&A' where V_USERMODIFICATION='bilal123'
or
Update GDO_INFO_ER set V_COMMENTAIRE='B#A' where V_USERMODIFICATION='bilal123'
I would like to insert & and # literally in the table.

View Replies !
Escape Charecters
Can anyone tell me ho to get certain charecters to be displayed.
When sending email with (') i get () instead. i.e.

This dosen't work becomes dosen

View Replies !
Escape Character
I dont know why the browser doesn't present the php string with some escape character like
, ....
For example: the string "Name
Address" should be printed out like
Name
Address

instead it prints out "Name Address".I tried other ones and do not work. Anyone know why?

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 !
How Can I Escape The XML Syntax
i have a textarea where users can input information about themselves. They can even edit the texts (making the texts bold, italic...). It works fine when i try to add the info into the db. But when i try to display the info from the db, it displays some characters like \" whatever.

I used stripslashes, but it didn't solve the problem. What do you advise me so that i can handle the XML special characters not to disturb my design??

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 !
Escape The % Sign
i tryed with addcslashes() and addslashes()

but it still just prints : "%" insted of "/%" .

View Replies !
Escape Slashes
I want to escape backslashes in the below query - DB is MS SQL Server so addslashes() no use. The problem is here... 'O'Co', MS SQL Server won't accept it. PHP Code:

INSERT INTO training(class_ID, ffnumber, firstname, surname, attended, passed, date_reg) VALUES(&#55619;&#57058;', 'ff18728', 'Ann', 'O'Co', 'No', 'No', {fn NOW()}) ESCAPE ''

Any ideas?

View Replies !
Escape Search
I'm trying to grab data from a database where the entry has a single quotation and then re-search based on that. Basically, I grab the entry: michael's car. But, I want to go back into the table and search for everything that has: michael's car. It seems that PHP always escapes the entries once I grab them from the database. Is there a way to avoid this?

View Replies !
Escape @ Sign
The subject may be confusing, but I am sure this is easy. My mind is blank on the solution. I have a script that returns a variable which will always include an email address. I want to process the variable to escape the "@" sign.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ex.

$email = "bob@bobsite.com";

I want to process the variable above so that it changes the value of $email to...

$email = "bob@bobsite.com";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I am guessing either preg_replace or preg_match is what I am looking for, but I have been unable to figure out how to change the variable by inserting the "" before the "@".

View Replies !
Javascript Escape In Php
I've used the javascript "escape()" function to prepare some data to be saved in a cookie. I'm now trying to read the data in PHP but not having much luck.

View Replies !
Escape Sequence
I have a small script that takes a user's email address and adds it to a text file, but I want it to write each e-mail on a new line I tried this code with no results: Code:

$file = fopen("/var/lists/test","a+");
fwrite($file, $_POST["email"] . ' '
);
fclose($file);

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 !
Escape All Posted Variables?
this works well enough when all the elements in $HTTP_POST_VARS are scalars, but it doesn't work so hot if one or more of them is an array:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
while(list($key,$val)=each($HTTP_POST_VARS)){$$key=htmlspecialchars($val);}
[/code]

So what I need is an easy way to tell if "$val" is an Array so that I can do something similar to each of its elements in turn.

View Replies !
Php Rawurldecode From Javascripts' Escape()
I'm sending some vars to php from javascript. These vars contain
special chars (like "&" ,",")and also turkish characters. Therefore
I'm using javascripts escape() function to be able to send them
properly. My problem is on the php side. I am using rawurldecode to
convert them back. However, Turkish characters like "I" (capital "I"
with a dot on top) for example still stay encoded as "%u0130".

My page is setup to handle turkish chars and if sent from a database,
display properly. I've googled for an answer and cant find anything.

I've also tried looking at base64 encoding from javascripts' end, to
again decode using base64Decode from php, but nothing seems to work
right.

View Replies !
Strings Escape Sequences
Is variable interpolation different from escape sequences in strings in PHP? PHP Code:

View Replies !
Escape $HTTP_ Vars
whats the best way to escape incoming post/get data Im using psedo code below, PHP Code:

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 !
How To Tell If Escape Behavior Is Turned On
Is there a programmatic way in PHP (using PHP 4) to tell if the
escaping apostraphes behavior is turned on when a request is submitted?
What I would like to do is insert a value into my db table, but only
apply escaping if PHP hasn't applied it for me ...

$v = $_REQUEST['val'];

if (escaping_disabled()) {
$v = escape($v);
}

insertIntoDB($v);

View Replies !
How Do I Escape Angle Brackets?
I have a line like this in some PHP code on my Web page:

$callthis =~ s/<[^>]*>//g;

When the page runs, I get this error:

Parse error: parse error, unexpected '<' in /Feedback.php on line 145

So I presume I must escape angle brackets somehow in the regular
expression. How do I do it? I tried putting a backslash in front of
each angle bracket, but that doesn't seem to work (same error).

The purpose of the statement is to remove HTML tags from the string.

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 !

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