-
Posts
81 -
Joined
-
Last visited
Everything posted by ianco
-
I get 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 add' ORDER BY pageid DESC LIMIT 20' at line 1
-
Hi all. I've been looking at this for several hours not with no progress. I feel it should be simple but I'm getting nowhere. Here's the problem. I want to provide a list of links where from a table called pages. When $title = "Dave's comment"; for example I get nothing back. If there is no apostrophe in the field it works fine. It's as though I can't find the field. $query = mysql_query("SELECT * FROM pages WHERE title = '$title' ORDER BY pageid DESC LIMIT 20"); while($row = mysql_fetch_assoc($query)) { $title = $row['title']; echo $title; } any ways around this? Thanks Ian
-
bingo, cheers
-
I'm not sure JOINS will work because the cell could contain e.g. "2,5,19,21" so i can have $range = "2,5,19,21"; but I want to change that into an array $arr = array($range);
-
Hi all, I want to create an array from the output of a table. In the table cell I have some numbers where for each number I would like to relate it to a value in another table. However using the code below I get Array ( [0] => "26","27","28","29","30","31" ) from the print_r($arr); meaning that $range ins't being treated as an array, and hence, the second query only gives one value. $showIng = mysql_query("SELECT * FROM recipe WHERE name = '$dish'") or die(mysql_error()); $rowShowIng = mysql_fetch_assoc($showIng); $range = $rowShowIng['keyno']; $arr = array($range); print_r($arr); foreach ($arr as &$value) { $getIng = mysql_query("SELECT * FROM keywords WHERE keyid = '$value'") or die(mysql_error()); $rowGetIng = mysql_fetch_assoc($getIng); echo $rowGetIng['ingredient']; } So, I want to know how I can create the array from $range Thanks
-
joe92, thanks I'll look into preg_replace_callback
-
xyph, you're not wrong, I previously had $pagecontent = preg_replace('#<h2>([^<]+)</h2>#i', "==$1==", $pagecontent); and you wouldn't line break a heading
-
thanks guys Xyph, your solution works but it can't handle line breaking tags i.e. <br> or <br />, it makes some of the tags disappear. Can you give me more info on the parser joe92 i need the nested tags so i don't think your way will work
-
Hi, I'm trying to turn '<div class="infobox"><div class="infoboxtitle">this is a title</div><div class="infoboxtext">example text</div></div> into [infobox][infoboxtitle]this is a title[/infoboxtitle][infoboxtext]example text[/infoboxtext][/infobox] so, using preg_replace i have: $pagecontent = preg_replace('#<div class="infoboxtitle">([^<]+)</div>#i', "[infoboxtitle]$1[\/infoboxtitle]", $pagecontent); $pagecontent = preg_replace('#<div class="infoboxtext">([^<]+)</div>#i', "[infoboxtext]$1[\/infoboxtext]", $pagecontent); $pagecontent = preg_replace('#<div class="infobox">([^<]+)</div>#i', "[infobox]$1[\/infobox]", $pagecontent); But it's not giving me anything back. Any idea where I'm going wrong? Thanks Ian
-
Hi, Sorry for the delay in getting back. Using the same code I just changed the function to function gallery($username){ echo "this is my ".$username; } the variable $username is available on all my pages but all I was seeing is: this is my Anyway, I'll have a play around and mark this thread as solved. Thanks Ian
-
Hi again, Although I haven't got an actual use for this yet I've been thinking. From the code that was helpfully provided, you can't put variables into the function, i.e., gallery($username). Is there a solution to this or should it actually work and I'm just being a spanner <?php $s='text, e.g. [!gallery!], that is contained in blog post'; $p=',\[!([^!]+)!\],'; $s=preg_replace_callback($p, function ($match) {return $match[1]();}, // calls gallery() $s); function gallery() {return '//function GALLERY was here//';} echo $s; ?>
-
Got it! it wasn't working because i had the function gallery() in another function. Thanks very much for the help!!!! Ian
-
Hey thanks for the replies. PLayful, the first example in your first reply works great and gives me the variable. I guess what I originally envisioned was using the variable in an include e.g., include($gallery.'php'), then have a function in that file. I think your second methods sound like a better idea. The second reply example 2 seems to kill the rest of my script but is a good idea and works on its own so I will have a play around and let you know
-
$somevariable would just be what is contained between [! and !] preg_replace may not be the most appropriate function
-
Hi, I want to be able to replace text, e.g. [!gallery!], that is contained in blog post and have the word 'gallery' as a variable $gallery so i can use it to fetch files/call a function. This is what I have so far: $rowblog[Content] = preg_replace("/\[\!(.*?)\!\]/","$somevariable", $rowblog[Content]); as far as I know the variable isn't being created. Any idea of a solution? Thanks Ian
-
Awesome, thanks very much!!! Naughty little asterisk!!!
-
this regex is: $regex = '#<figure><img src="([^\']*)" alt="([^\']*)" /><figcaption>([^\']*)</figcaption></figure>#'; $replace = '{{$1||$2||$3}}'; $pagecontent = preg_replace($regex, $replace, $pagecontent); except when I have two figures it cocks up.
-
I think it's the correct way around but here's the reverse anyway $regex = "#{{([^|]*)\|\|([^|]*)\|\|([^|]*)}}#"; $replace = '<figure><img src="$1" alt="$2" /><figcaption>$3</figcaption></figure><p>'; $content = preg_replace($regex, $replace, $content);
-
Sorry my first post doesn't make too much sense I'm entering (or starting with) <figure><img src="http://example.com/Cat.bmp" alt="text" /><figcaption>text</figcaption></figure> and I want it to turn it into {{http://variouspictures.tk/wp-content/uploads/2011/07/Cat.bmp||text||text}} this works fine when there is only one figure but when I have two figures i.e., <figure><img src="http://example.com/Cat.bmp" alt="text" /><figcaption>text</figcaption></figure> <figure><img src="http://example.com/Cat.bmp" alt="text" /><figcaption>text</figcaption></figure> i only get {{http://variouspictures.tk/wp-content/uploads/2011/07/Cat.bmp" alt="text" />text instead of {{http://variouspictures.tk/wp-content/uploads/2011/07/Cat.bmp||text||text}}{{http://variouspictures.tk/wp-content/uploads/2011/07/Cat.bmp||text||text}}
-
Hi all, So, I have this code stored in a database: <figure><img src="http://example.com/Cat.bmp" alt="text" /><figcaption>text</figcaption></figure> and i use regex php to turn it into the following in a text editor: $regex = "#{{([^|]*)\|\|([^|]*)\|\|([^|]*)}}#"; $replace = '<figure><img src="$1" alt="$2" /><figcaption>$3</figcaption></figure><p>'; $content = preg_replace($regex, $replace, $content); This works fine except when I want to insert two figures. So if i have two figures separated by a line the regex changes it to {{http://variouspictures.tk/wp-content/uploads/2011/07/Cat.bmp" alt="text" />text Can anyone explain to me why this happens and suggest a solution. Thanks Ian
-
I played about with it a bit more and found that in the $regex line i needed \ (slash) before the apostrophe. so, here it is. thanks guys $regex = '#<figure><img src="([^\']*)" alt="([^\']*)" /><figcaption>([^\']*)</figcaption></figure>#'; $replace = '{{$1||$2||$3}}'; $pagecontent = preg_replace($regex, $replace, $pagecontent);
-
Hi Sorry to bang on about this but i'm still not having any luck with this. $regex = "#<figure><img src='([^']*)' alt='([^']*)' /><figcaption>([^']*)</figcaption></figure>#"; $replace = "(($1**$2**$3))"; $pagecontent = preg_replace($regex, $replace, $pagecontent); no curly brackets now and still won't preg_replace any ideas? Thanks folks Ian
-
for some reason $replace = "{{$1||$2||$3}}"; is killing my script. I just get a blank page unless I delete it. Why would this be?? Ian
-
Sorry, I've just replaced input and output from the previous example above with content. Either way I want to reverse the first situation so that my HTML turns into short hand: {{http://en.wikipedia.org/wiki/File:Wiki.png||wikipedia logo||This is the wikipedia logo}}
-
I want to now reverse it. SO, I've got $regex1 = '{{$1||$2||$3}}'; $replace1 = '#<figure><img src="([^<]+)" alt="([^<]+)" /><figcaption>([^<]+)</figcaption></figure>#i'; $content = preg_replace($replace, $regex, $content); but this isn't working. I must be near... Any ideas? Thanks Ian