PHP - Get Rid Off The Last Delimiter
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 Similar TutorialsI 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 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 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; } 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 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 ''; } preg_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? |