I've been having trouble with an UPDATE statement in the code below. The problem is that each time I submit the form to update an existing record in the products table, the records won't update. When I submit the form there is no error message and it redirects to the correct URL, defined after query: `header("Location: " . $config_basedir . "glass/?id=" . $validentry);` I have tried using the preg_replace php function to replace any single quotes that may prematurely end the UPDATE command. This hasn't resolved the problem. Advice would be appreciated. Thanks! <?php session_start(); require("../go/config.php"); if(isset($_SESSION['USERNAME']) == FALSE) { …

Member Avatar
Member Avatar
+0 forum 3

I am developing a script that takes an article, searches the article for a "keyword" and then randomly replaces that keyword with an anchor link. I have the script working as it should, however I need to be able to have an array of "replacements" for the function to loop through and insert at the random location. So the first random position would get array value 1. The second random position would get array value 2. The third random position would get array value 3. etc... public function replace_random ($str, $search, $replace, $n) { // Get all occurences of $search …

Member Avatar
Member Avatar
+0 forum 7

Hi all. AM having a little issue with regex. Not one of my strongest skills! I'm trying to produce a simple translation system that doesn't require arrays, gettext etc. It basically has this structure: $content=<<<CONTENT <p>{{Dyma destun||Here's some text}}</p> ... CONTENT; So the page content is held in a var via heredoc syntax. That's all well and good. My index.php is this: include('common/config.php'); include('common/functions.php'); include($page_server); include('templates/common.php'); echo translate($header); echo translate($content); echo $footer; The translate function in the functions.php file is this: function translate($content){ $l = $_SESSION['lang']; $pattern = array('en'=>'/\{\{.[^(\}\})]*\|\|/','cy'=>'/\|\|.[^(\{\{)]*\}\}/'); $brackets = array('en'=>'}}','cy'=>'{{'); $content = preg_replace($pattern[$l],'',$content); $content = str_replace($brackets[$l],'',$content); return $content; …

Member Avatar
Member Avatar
+0 forum 6

Hi I am having trouble understanding how the pre_replace function works. I am using a script which has the following line: $ret = preg_replace("#(@|telefone|e-mail|.com|skype|.com.br|fone|www.|hotmail|yahoo|ig|aol|uol|gmail|bol|msn|MSN)#i", "\\1scriptolutionreplacement", $ret); What is happening is that any word with for example the letters ig or uol in it is getting caught. Is there a way to alter this line so that it is only unique/complete word such as ig or uol that are amended? Hope this makes sense and thank you in advance for any advice. Regards Mark

Member Avatar
Member Avatar
+0 forum 2

Hi all, I want to replace these charachters: Æ,Ø,Å,æ,ø,å, with, AE,OE,AA,ae,oe,aa I thoght I could use preg_replae this way to accomplish that, but if i write this word in the form: "Bælter" - All that is left to be inserted into the DB is "B" - So I am removing everything from the special charachter away from the string... This is what i have: [CODE] $search = array('/Æ/', '/Ø/', '/Å/', '/æ/', '/ø/', '/å/', '/ /'); $replace = array('AE', 'OE', 'AA', 'ae', 'oe', 'aa', '-'); $vare_gruppe_url = preg_replace($search,$replace,$vare_gruppe_url); [/CODE] I am using utf-8 - and have read that preg_replace doesnt work …

Member Avatar
Member Avatar
+0 forum 4

Hi, i am new to PHP but i have some common knowledge to recognizing commands and such. in my page i have code like this [CODE]<div class="page_column page_column_first" id="page_column_1" style="width: 499px;"><div class="page_block_container" id="page_block_759"><div class="disignBoxFirst"> <div class="boxFirstHeader"><div class="dbTitle">Up and Coming</div></div> <div class="boxContent"><div class="dbContentHtml"><p>This is a placeholder for up and coming news to be edited at News Time.</p></div></div>[/CODE] So whatever class it is linked to say "boxContent" which is the name of a section on a .css file on the server, i want it take the information under that header and place it on that same line and doing something like [code]preg_replace[/code] …

Member Avatar
Member Avatar
+0 forum 3

Hello, I'm trying to replace {include %filename.php%} with that file from the server. I can get this to work file if the file is plan html text using the function below. [CODE] $str = "This would be a paragraph of text. {include %news.php%}"; preg_replace_callback("/\{include %(.*?)\%}/", function($m) { return file_get_contents(CORE . 'includes/' .$m[1]); }, $str);[/CODE] But if the included file contains php code for example [CODE]<? echo "Hello World"; ?>[/CODE] It doesn't work, it just prints "echo hello world". If i change [I]return file_get_contents[/I] to [I]include[/I] it includes the file before my string of text. Unlike how the string is originally …

Member Avatar
Member Avatar
+0 forum 24

Hello, I'm looking for some help on the following line of code, it keeps throwing an error. [I]Parse error: syntax error, unexpected T_FUNCTION Line 168.[/I] The code below is line 168. [CODE]$content = preg_replace_callback("/\{include '(.*?)'}/", function($m) { return file_get_contents(CORE . 'includes/' .$m[1]);}, $str);[/CODE] Any ideas?

Member Avatar
Member Avatar
+0 forum 1

Hi, How can I use preg_replace to determine if a string contains a word beginning with a pattern, and if it does, remove it? Basically I want to capture query strings from a search, but throw away search modifiers. For example, the search query string: site:daniweb.com query would just become query In this case, I want to remove all words in the string that begin with 'site:'. TIA!

Member Avatar
Member Avatar
+0 forum 9

I've tried this a number of different ways and I've even downloaded the Regular Expression reference sheet from addedbytes.com, but I just can't figure out how to move this eregi_replace() statement into a preg_replace() statement. I've read and understood the delimiter requirements for preg_replace(), but I think the problem is the modifiers. How to I know which modifier to use for this function? I've tried \A, \b, and \e, but none seem to work. I think there's something simply I'm missing. [code=php]$bodytag = '%%BODY%%'; $header = eregi_replace($bodytag . '.*', '', $temp); $footer = eregi_replace('.*' . $bodytag, '', $temp);[/code] I've tried …

Member Avatar
Member Avatar
+0 forum 4

I have the following code witch is used to display HTML from an XML file. The XML file itself comes from a form POST where a "\" is added in after various HTML tags. Is there anyway I can modify the script below to hide/remove the "\" when the XML contents are displayed? [CODE] <?php $file="data/_data1.xml"; $xmlDoc = new DOMDocument(); $xmlDoc->load($file); //shows specific node data $x=$xmlDoc->getElementsByTagName( "_tag_1" ); $x=$x->item(0)->nodeValue; //show result echo $x; echo "<br />"; ?> [/CODE] I've tried using [B]preg_replace[/B] but it still doesn't remove the "\" [CODE] <?php <?php $file="data/_data1.xml"; $xmlDoc = new DOMDocument(); $xmlDoc->load($file); //shows specific …

Member Avatar
Member Avatar
+0 forum 6

Hi all, preg-Replace has stumped me again. I'm just too thick to get it. This is my problem: I have two files. File 'newvalues.php' with an array like so: [CODE].... $lang['this_key'] => 'blah blah blah'; $lang['another_key'] => 'rhubarb rhubarb'; $lang['something_else_key'] => 'twitter twitter'; ....[/CODE] And another file: 'template.php' like so: [CODE]$lang = array( .... 'this_key' => 'some other value', 'something_else_key' => 'an old value', 'another_key' => 'spaghettiness', .... };[/CODE] What I need is some preg_replace stuff to replace the values in the template.php file with the values in the newvalues.php file. Before you ask, no I have no control over …

Member Avatar
Member Avatar
+0 forum 11

So I got most of the code working, but what I am trying to do, is say someone post the following This is a great youtube video [url]http://www.youtube.com/watch?v=pkrM7x0_fcI&feature=channel[/url] what do you think. I want it to turn the youtube link to [url]http://www.youtube.com/v/pkrM7x0_fcI[/url] but keep the text that they typed so it should look like this This is a great youtube video [url]http://www.youtube.com/v/pkrM7x0_fcI[/url] what do you think. If anyone can help that would be great... [code=php] if (preg_match_all('#(http://www.youtube.com)?/(v/([-|~_0-9A-Za-z]+)|watch\?v\=([-|~_0-9A-Za-z]+)&?.*?)#i',$youtubeinput,$output)) { foreach ($output[4] AS $video_id) { $youtubeinput = "<a class=\"flashvideo\" href=\"http://www.youtube.com/v/".$video_id."\">http://www.youtube.com/v/".$video_id."</a>"; } } [/code]

Member Avatar
Member Avatar
+0 forum 4

Hi, I am using cURL to grab the contents of a webpage which contains a table. I am trying to make an array out of the table contents, with the column headings as the array keys. Unfortunately the first row of the table, before the headers, has pagination which is messing it all up. The row in question is as follows: [CODE]<tr class="DGListPager" align="center"> <td colspan="6"><b>Page: </b><span>1</span>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl01&#39;,&#39;&#39;)">2</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl02&#39;,&#39;&#39;)">3</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl03&#39;,&#39;&#39;)">4</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl04&#39;,&#39;&#39;)">5</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl05&#39;,&#39;&#39;)">6</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl06&#39;,&#39;&#39;)">7</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl07&#39;,&#39;&#39;)">8</a></td> </tr>[/CODE] I have tried using preg_replace and preg_filter to simply get rid of the extra row, but I haven't had any luck. I am afraid that …

Member Avatar
Member Avatar
+0 forum 1

Im trying to use a regular expression backreference to reference a hash key. Here's an example of the non working code so you can see what I'm trying to achieve (I hope!): [CODE] $str="String of text containing item1 and item2"; $x['item1']="Item 1"; $x['item2']="Item 2"; $str=preg_replace("/item1/","$x[\${1}1]",$str); print $str; [/CODE] I want to get the result "String of text containing Item 1 and Item 2" - it must use the backreference to get the result out of the hash. Anyone got any ideas? Thanks in advance, Matt.

Member Avatar
Member Avatar
+0 forum 2

I have a string contains sequences of 0 and 1. I need to replace all zero sequences whose length less than 5, into number 1 with same length. The zero sequences with length 5 or more should be left as is. For example source : 11000001100010011000001 result : 11000001111111111000001 [CODE] <?php $string = '11111000011100000110010'; $pattern = '/0{1,4}/i'; $replacement = '1'; // what should I put here? echo preg_replace($pattern, $replacement, $string); ?> [/CODE] Thanks

Member Avatar
Member Avatar
+0 forum 3

Ok. I have ZERO PHP Knowledge, still good in editing php and all that stuff. Only know copy paste and have no knowledge what that means. Still would try to explain my problem. I use variable to fetch data from mysql. Ex. my url is [url]http://www.example.com/venue.php?vcity=New[/url] York. Now, I want to replace New York with New-York. The real url I am trying to get is [url]http://www.example.com/venue-new-york.php[/url]. For that I added code in htaccess [CODE=PHP]RewriteRule ^venue-([^/]*)\.php$ /venue.php?vcity=$1 [L][/CODE] I Know what I added in htaccess is mostly perfect. Now, I am using smarty so would be able to do lower case …

Member Avatar
Member Avatar
+0 forum 6

I am planning to use preg_replace to remove some unwanted stuff from dynamic string $mystring: <ul><li><a href="http://www.url.com/wiki/How_to_fix_erection_problems_after_prostate_surgery&amp;diff=335&amp;oldid=prev">How to fix erection problems after prostate surgery</a></li> <li><a href="http://www.url.com/wiki/Wikipenis:Community_Portal&amp;diff=334&amp;oldid=prev">Wikipenis:Community Portal</a></li> </ul> This string is generated from an RSS reader. (The url has obviously been replaced to make sure no one thinks this is a spam post) What I need to do is figure out a way to go through the string and remove the "&amp;diff=335&amp;oldid=prev" and the "&amp;diff=334&amp;oldid=prev" I can not just use str_replace() because those two constantly change. However I assume it is possible with a regular expressions I just don't know …

Member Avatar
Member Avatar
+0 forum 2

hey all. I am trying to do validation via PHP for submitted forms. Below is my own code, please comment if its the correct method or not. However, I tried so many ways to have the /n or /r added, but I cant get to it. Its just to make a new paragraph. Currently, it does the validation, but once I hit the enter key twice, for a new paragraph, it doesnt work the way it should. Any help and advice appreciated. Thanx [CODE] function validateText($data){ //if it's NOT valid if(ereg('[^a-zA-Z0-9 .,-_]', $data)) return false; //if it's valid - Must …

Member Avatar
Member Avatar
+0 forum 4

Hi there, I am building a blog at the moment i have a amazing script that search a post for the images in it. So i can just setup a post template, call the images that are in the post and go. In this way i put the images unedited and unresized in the post and the template will make everything nice and smooth.:) The thing is that the function works great, it produces a nice image with the image tags. Only the thing is: I don't want the whole image wrapped up in a image tag, i want only …

Member Avatar
Member Avatar
+0 forum 5

Hi folks, I'm looking for a function, similar to str_replace that replaces just the first occurance of a specified string. I have found such a function: [url]http://www.help2go.com/Tutorials/Programming/PHP_:_How_to_replace_only_the_first_occurrence_in_a_string_with_str_replace.html[/url] However, this does not take into consideration of 'search from an initial position'. My interest is with regard to replacing strings within a php array (for translation purposes) in phpBB language files: .... 'THIS_KEY' => 'My string', 'THIS_KEY_1' => 'My string 1', 'THIS_KEY_2' => 'My string 2', .... I want to find the key within the file (I load the whole file into a string via file-get_contents), and from that point replace the …

Member Avatar
Member Avatar
+0 forum 16

The End.