PHP - Preg_match - Delimiter Must Not Be Alphanumeric Or Backslash
I am working on taking out the Deprecated functions from my site so while replacing ereg with preg_match I get the below error. Per a message I found on the internet it says to replace ereg with preg_match and everything should work. Can anyone assist me with fixing this error?
Error: Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash Part where error is contained if (preg_match('enum.(.*).', $row['Type'], $match)) { $opts = explode(',', $match[1]); foreach ($opts as $item) $finalResult[] = substr($item, 1, strlen($item)-2); } Full Function function getEnumOptions($table, $field) { global $db; $finalResult = array(); if (strlen(trim($table)) < 1) return false; $query = "show columns from " . $db['tickets_slave']->escapeSimple($table); $res =& $db['tickets']->query($query); if (PEAR::isError($res)) { throw new TixException($_SERVER['SCRIPT_NAME'] . ":", TixExceptionCodes::UNKNOWN_ERROR); } else { try { while ($res->fetchInto($row)) { if ($field != $row["Field"]) { } else { //check if enum type if (preg_match('enum.(.*).', $row['Type'], $match)) { $opts = explode(',', $match[1]); foreach ($opts as $item) $finalResult[] = substr($item, 1, strlen($item)-2); } } } } catch (TixException $ex) { throw new TixException($_SERVER['SCRIPT_NAME'] . ":", TixExceptionCodes::UNKNOWN_ERROR); } } return $finalResult; } Similar TutorialsThis topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347719.0 Please help me with this code. It keep appear in my website. "Warning: preg_match() [function.preg-match]: No ending delimiter '.' found in /home/kengsite/public_html/wp-content/plugins/statpress/statpress.php on line 1184" And this is how the line look like. if (!preg_match(".ico$", $urlRequested)) { return ''; } Hi All, I am trying to create a PHP code that will run a form, however i keep getting the error message Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in D:\xampp\htdocs\HFCC\Scripts\mailprocess.php on line 55 Invalid email address entered. Go Back and try again attached is the complete copy of the code i am using, i have an email text box and label with the id 'email' also my method is POST and my action is Scripts/mailprocess.php. Please let me know if you need any additional details. Any help will be much appreciated. Thanks The issue I'm having is when the returned data has data to place inside of fields it does but when there isn't data then it shows a backslash and I'm not sure why? Any ideas? Code: [Select] <form action="#" id="bioForm" > <?php while ($row = mysqli_fetch_array($groupsResult, MYSQLI_ASSOC)) { echo "<fieldset> <legend>" . $row['groupName'] . "</legend>"; $fieldsResult = mysqli_query ( $dbc, sprintf($fieldsQuery,$row['ID']) ); echo $fieldsQuery; while ($row2 = mysqli_fetch_array($fieldsResult, MYSQLI_ASSOC)) { echo "<div class=field required>"; if ($row2['inputType'] == "text") { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<input type=text name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=text biofield title=" . $row2['fullName'] . " value=" . $row2['content'] . " />"; } elseif ($row2['inputType'] == "textarea") { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<textarea name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=textarea biofield title=" . $row2['fullName'] . " >" . $row2['content'] . "</textarea>"; } else { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<select name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=dropdown biofield title=" . $row2['fullName'] . " >"; echo "<option value= >None</option>"; if ($styleID == 1 || $styleID == 2 || $styleID == 6) { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID = 3 ORDER BY characters.characterName"; } else { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID IN (1,2,6) ORDER BY characters.characterName"; } $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $manager_row = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=\"".$manager_row['ID']."\" "; if($manager_row['ID'] == $row2['content']) { print " SELECTED"; } print ">".$manager_row['characterName']."</option>\r"; } echo "</select>"; } echo "</div>"; } echo "</fieldset>"; } ?> <fieldset> <input type="hidden" name="defaultCharID" id="defaultCharID" value="<?php echo $defaultCharID; ?>" /> <input type="submit" class="submit" id="editBio" title="Edit Bio" value="Edit Bio" /> </fieldset> </form> Code: [Select] <?php session_start(); // Access the existing session // Include the database page require ('../../inc/dbconfig.php'); $defaultCharID = $_SESSION['defaultCharID']; $styleIDQuery = " SELECT characters.styleID FROM characters WHERE characters.ID = '" . $defaultCharID . "'"; $styleIDResult = mysqli_query ( $dbc, $styleIDQuery ); // Run The Query $row = mysqli_fetch_array( $styleIDResult, MYSQL_ASSOC ); $styleID = $row[ 'styleID' ]; $groupsQuery = " SELECT groups.* FROM groups WHERE groups.styleID = '" . $styleID . "' ORDER BY groups.ID"; $groupsResult = mysqli_query ( $dbc, $groupsQuery ); // Run The Query $fieldsQuery = " SELECT fields.*, fieldsContent.content FROM fields INNER JOIN fieldsContent ON fields.ID = fieldsContent.fieldID WHERE fields.styleID = '". $styleID . "' AND fields.groupID = '%d' AND fields.statusID = 1 AND fieldsContent.characterID = '". $defaultCharID . "'"; ?> For a very 'loose' email address validator, does the following regex need the backslash before the dot?
^\S+@\S+\.\S+$
(Checks for anything@anything.anything but I'm gonna change that to anything.anything to make it even 'looser')
I tested with and without the backslash using rubular.com and it seems superfluous but I'd like a second opinion or two please.
ALSO: does rubular.com use the right engine to be correct for php? I hope so coz it's the first time I've been able to fully understand some regexes I've been blindly implementing for some time!
Many thanks in advance
What is the correct way to use the backslash here? I am using an ftp script and retrieving the brand directory name through url. I want to catch it if they try to use \ in the url to list all directories. Code: [Select] elseif($_GET[f]=="\") { echo "You have entered an invalid vendor."; $_SESSION['brand_path'] = "INVALID"; } Is there a way to trim everything off in front of the last backslash in the string? Code: [Select] $trimFile = $fList[$i]; Example: In this path: \\\\myftp/downloads/tom/work/word_docs\\legal\test.pdf I only want to display test.pdf. Thanks, Jake When I say something must be "alphanumeric", what do YOU define that as being? To me, it means ONLY Upper-Case Letters, Lower-Case Letters, and Numbers (i.e. A-Z, a-z, 0-9). Debbie hi i have got the following issues i am using the following code. Code: [Select] <?php //DB CONNECTION $ROWS = "id,firstname,lastname"; // explode at the comma and insert into an array $test = explode("," , $ROWS); //adds array test to the var sam $sam = array($test); // querys the database $new = mysql_query("SELECT * FROM {$DB_TABLE}"); // while loop to loop through selected fields while ($row = mysql_fetch_array($new)) { foreach ($sam[0] as $v) { echo $row[$v] . $DELIMITER . "<br />"; } echo "<br />"; } ?> This will output the following . Code: [Select] 834(|)Step(|)Thompson(|) 835(|)Lucy(|)kim(|) 836(|)Iwan(|)Will(|) 837(|)Sarah (|)Good(|) what i am struggling with is i want to get rid off the last delimiter so it would be Code: [Select] 834(|)Step(|)Thompson 835(|)Lucy(|)kim 836(|)Iwan(|)Will 837(|)Sarah (|)Good i have tried using Code: [Select] // while loop to loop through selected fields while ($row = mysql_fetch_array($new)) { foreach ($sam[0] as $v) { $test = $row[$v] . $DELIMITER; echo substr($test, 0, -1); } echo "<br />"; } but this gets rid off the delimiter for all off them??? This will output the following . Code: [Select] 834Stephompson 835Lucykim 836IwanWill 837SarahGood ideally i would like each row to be its own stored together. Any Help Please I have a user input string via GET variable that I want to always make sure falls within the constraints of type of variable its set for, which is a md5 hash. So I want to put together using preg_match or something using a regex construct (even though I suck with regex) to verify that all the characters in the string are valid characters for a md5 hash, where if its not then I want to kick back an error. The idea of making something like that isnt the issue for me so much as not knowing whether or not an md5 has is strictly alphanumeric or if it can possibly even if one in a million chance have something else from an underscore to a exclamation point or other characters. Ive tried to find out searching google and other sites for an answer but my search terms I guess are way to open to find something distinctly close to what I am looking for answer wise, so I figured I'd give you guys a shot see if anyone knows. I'm having trouble with a role in a wordpress site that I made I think the script was that I installed another version, so I some adjustments in it, among those changes have modified this function Quote if (@$_GET['src'] && !@$PHPTHUMB_CONFIG['allow_local_http_src'] && eregi('^http://'.@$_SERVER['HTTP_HOST'].'(.+)', @$_GET['src'], $matches)) { $phpThumb->ErrorImage('It is MUCH better to specify the "src" parameter as "'.$matches[1].'" instead of "'.$matches[0].'".'."\n\n".'If you really must do it this way, enable "allow_local_http_src" in phpThumb.config.php'); } for this: Quote (@$_GET['src'] && !@$PHPTHUMB_CONFIG['allow_local_http_src'] && preg_match('^http://'.@$_SERVER['HTTP_HOST'].'(.+)', @$_GET['src'], $matches)) { $phpThumb->ErrorImage('It is MUCH better to specify the "src" parameter as "'.$matches[1].'" instead of "'.$matches[0].'".'."\n\n".'If you really must do it this way, enable "allow_local_http_src" in phpThumb.config.php'); } It was supposed to make some images appear as thumbnails on the home page my site, but they do not appear and I got the following error: Quote Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /home/pontocom/public_html/wp-content/themes/Comfy/scripts/phpThumb/phpThumb.php on line 160 Is there some way that I can take to fix this error? This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320039.0 I am trying to split a variable only if it has an integer. Here is what I want to do: $id = 1234-54678; should be split into and then placed into two variables: $id1 = 54678; $id2 = 1234; Sometimes the variable may not have a delimiter in which case I would like it to be $id1 example: $id = 54678; should go directly to $id1 = 54678; I am a php rookie and don't know which way is best to do this (explode, split, etc.) so I would appreciate any help you can give me. Hi New to php code, been trown in at the deep end. Keep getting error message Warning: preg_replace(): No ending delimiter it is to do with these 3 lines only $is_sera = preg_replace("'","\"", $is_sera); $is_sera = preg_replace("%","", $is_sera); $is_sera = preg_replace("\?","", $is_sera); can any one tell me what the ending delimiter error means/is thanks in advance Hi Looking to create an ID which only contains alpha-numeric (no special chars). I looked to generate random bytes and then encode in base64 but base64 contains = + /. The below seems to do it but not sure if bin2hex can return non alpha numeric? bin2hex(openssl_random_pseudo_bytes(18)); Edited December 18, 2018 by mds1256 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=356719.0 Jelly Bellys. So there are "recipes" of ones you can eat at the same time. The most well-known one is probably mixing a couple peanut butter jelly beans with a couple grapes. I have to say it's pretty good because they actually do taste like peanut butter and grapes, but I have one issue: the peanut butter flavor is too weak compared to the grape. Instead of a 1-1 ratio it takes more like 3-1. Weird thing, this has got to be the most famous recipe so why isn't it listed on their site? I see candy apple, tiramisu, and lemon meringue pie, but nothing about peanut butter and jelly sandwiches. Are they just not popular anymore? Personally I prefer peanut butter and chocolate (Nutella, specifically) but whatever. Which can't be that weird because Reese's is popular... Mind you peanut butter + Nutella sandwiches don't really taste like Reese's candies, but that could just be because of the type of chocolate. Like they use milk or dark chocolate while Nutella is based on hazelnut. Which reminds me, I have a jar of it in the cupboard, but it's been so long since I've used it that it might have turned into an oily mess by now. I know it's just the various oils and such separating but it looks like someone poured a teaspoon or two of water right into it and that just kinda puts me off the whole thing. Same for peanut butter for that matter except the "water" isn't clear. Dirty water. And mixing everything back together isn't so bad but it gets the knife dirty on the handle, which really bothers me because then my fingers get dirty and I have to stop what I'm doing and go wash my hands. I already do that enough each day, I don't want to make more reasons for me to do so. But beyond the oily mess there's also stuff getting stale. Stale Nutella is a pain because it's stiff and hard to deal with, and the kind of bread I like most is very soft and easily rips apart so spreading it on can be a real labor. Best method I've found is to spread a little bit on at a time but it takes so long to cover the whole face. Fine, it's a good sandwich, but in that same time I could have done something else. Maybe there's something in the freezer I could quickly heat up, or maybe there's some leftovers in the fridge I could eat. And if not there's pretty good odds that I need to go to the grocery store anyways. Ah, sorry. Forgot why I'm here. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=358112.0 I need to create a SEO friendly string only from alphanumeric and characters of my native language. It is sinhala. My expected string should be something like this: $myString = "this-is-a-දහසක්-බාධක-දුක්-කම්කටොලු-මැදින්-ලෝකය-දිනන්නට-වෙර-දරන"; I am using a function to create the string like this. And that function is as follow: function seoUrl($string) { //Lower case everything $string = strtolower($string); //Make alphanumeric (removes all other characters) $string = preg_replace("/[^a-z0-9_\s-]/", "", $string); //Clean up multiple dashes or whitespaces $string = preg_replace("/[\s-]+/", " ", $string); //Convert whitespaces and underscore to dash $string = preg_replace("/[\s_]/", "-", $string); return $string; } This function only works for English characters and output of above string as below: $title = seoUrl("this-is-a-දහසක්-බාධක-දුක්-කම්කටොලු-මැදින්-ලෝකය-දිනන්නට-වෙර-දරන"); echo $title; // this-is-a-
I modified this function using `mb_ereg_replace` as below: function seoUrl($string) { //Lower case everything //$string = strtolower($string); //Make alphanumeric (removes all other characters) $string = mb_ereg_replace("/[^a-z0-9_\s-]/", "", $string); //Clean up multiple dashes or whitespaces $string = mb_ereg_replace("/[\s-]+/", " ", $string); //Convert whitespaces and underscore to dash $string = mb_ereg_replace("/[\s_]/", "-", $string); return $string; } But is not working for me. Can anybody tell me how to modify above function to get all my characters (including my native language characters) Hope somebody may help me out. Thank you. Edited January 28, 2019 by tharapreg_replace() asks that "Delimiter must not be alphanumeric or backslash" in the pattern. So I changed $new_text = preg_replace($_POST['withthis'] ,$_POST['withthis'],$_POST['text']); to this $replacethis = $_POST['replacethis']; $new_text = preg_replace("/$replacethis/",$_POST['withthis'],$_POST['text']); It works fine, but out of curiosity, is there any way to have the POST variable as a parameter directly, and why does it not work? Just to try it, I attempted: "/$_POST['withthis']/" and $_POST["/'withthis'/"] and both do not work. str_replace is a better option I think, but I am just trying to get a better understanding of this delimiter rule. Thanks for your time! Hi Guys I've been trying to work on my OS Commerce site, but for some reason I'm getting this error on the main index.php page. Welcome Guest! Would you like to log yourself in? Or would you prefer to create an account? Feel free to click any of the links below to access the main categories. Warning: strpos() [function.strpos]: Empty delimiter. in /var/www/vhosts/XXXXXX.co.uk/httpdocs/shop/index.php on line 319 319 shows this: if (isset($cPath) && strpos('_', $cPath)) { Any ideas where this error comes from? |