
liamdawe
Members-
Posts
16 -
Joined
-
Last visited
Everything posted by liamdawe
-
Sorry to bump, but I am still stuck on this. What would be the best way to replace nested tags like that before the normal img tag converter?
-
That's what I am trying to do in the code above, but it seems to not work correctly to the point of not parsing certain urls at all.
-
Adjust search so it only finds rows with all words?
liamdawe replied to liamdawe's topic in PHP Coding Help
Thanks! -
Hi all currently I am parsing some simple bbcode like urls, images, bold etc. I have just added it so all images are turned into links to themselves so if the image is too big they can click on it for the full picture. The problem is if someone wants a picture to link to something other than itself that now doesn't work. I am trying to counter it by parsing images that have a manual url attached to them first like so: $find = array( "/\[url\=(.+?)\]\[img\](.+?)\[\/img\]\[\/url\]/is", ); $replace = array( "<a href=\"$1\" target=\"_blank\"><img src=\"$2\" class=\"bbcodeimage img-polaroid\" alt=\"image\" /></a>", ); $body = preg_replace($find, $replace, $body); The problem is it seems to mess up the rest of the url parsing, is there something I am doing wrong? This code is directly after to parse normal links, the above code seems to also mess this up: $find = array( "/\[url\=(.+?)\](.+?)\[\/url\]/is", "/\[url\](.+?)\[\/url\]/is" ); $replace = array( "<a href=\"$1\" target=\"_blank\">$2</a>", "<a href=\"$1\" target=\"_blank\">$1</a>" ); $body = preg_replace($find, $replace, $body);
-
Hi all, I am currently trying to upgrade my websites search function, currently it will just list every article it finds with any of the words searched using PDO MySQL like so: $db->sqlquery("SELECT a.article_id, a.`title` , a.author_id, a.`date` , a.guest_username, u.username FROM `articles` a LEFT JOIN `users` u ON a.author_id = u.user_id WHERE a.active =1 AND MATCH ( a.`title` ) AGAINST ( ? IN BOOLEAN MODE ) ORDER BY a.date DESC LIMIT 0 , 30", array($search_text)); $found_search = $db->fetch_all_rows(); What I want to do is have a second option, where it searches for rows that have all of the words in it not just any of the words. $search_text contains the list of words separated by a space. Is this possible? Thanks!
-
Wow so glad I came back here, that was quite genius and works exactly as expected, thanks a bunch!
-
Currently I am using a custom-made simple bbcode parser I need to adjust to not parse anything inside code tags, so these: [code]do not parse any bbcode here like [b]this[/b][/code] I want nothing to be parsed inside those. My current code: function bbcode($body, $article = 1, $parse_links = 1) { if ($parse_links == 1) { $URLRegex = '/(??<!(\[\/url\]|\[\/url=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespace in front $URLRegex.= '('; // Start capturing URL $URLRegex.= '(https?|ftps?|ircs?):\/\/'; // Protocol $URLRegex.= '[\w\d\.\/#\_\-\?:=]+'; // Any non-space character $URLRegex.= ')'; // Stop capturing URL $URLRegex.= '(??<![.,;!?:\"\'()-])(\/|\[|\s|\.?$))/i'; // Doesn't end with punctuation and is end of string, or has whitespace after $body = preg_replace($URLRegex,"$2[url=$3]$3[/url]$5", $body); $find = array( "/\[url\=(.+?)\](.+?)\[\/url\]/is", "/\[url\](.+?)\[\/url\]/is" ); $replace = array( "<a href=\"$1\" target=\"_blank\">$2</a>", "<a href=\"$1\" target=\"_blank\">$1</a>" ); $body = preg_replace($find, $replace, $body); } else if ($parse_links == 0) { $find = array( "/\[url\=(.+?)\](.+?)\[\/url\]/is", "/\[url\](.+?)\[\/url\]/is" ); $replace = array( "$2", "$1" ); $body = preg_replace($find, $replace, $body); } // remove the new line after quotes, stop massive spacing $body = str_replace("[/quote]\r\n", '[/quote]', $body); // stop lists having a big gap at the top $body = str_replace("[ul]\r\n", '[ul]', $body); // Quoting an actual person, book or whatever $pattern = '/\[quote\=(.+?)\](.+?)\[\/quote\]/is'; $replace = "<blockquote><cite>$1</cite>$2</blockquote>"; while(preg_match($pattern, $body)) { $body = preg_replace($pattern, $replace, $body); } // Quote on its own $pattern = '/\[quote\](.+?)\[\/quote\]/is'; $replace = "<blockquote><cite>Quote</cite>$1</blockquote>"; while(preg_match($pattern, $body)) { $body = preg_replace($pattern, $replace, $body); } // replace images and youtube to the correct size if its a comment or forum post (less space!) if ($article == 0) { $find = array( "/\[img\]http\:\/\/img\.youtube.com\/vi\/(.+?)\/0\.jpg\[\/img\]/is", //youtube videos done by the old tinymce plugin... "/\[img\](.+?)\[\/img\]/is", "/\[img=([0-9]+)x([0-9]+)\](.+?)\[\/img\]/is", "/\[media=youtube\](.+?)\[\/media\]/is", // This is for videos done by xenforo... "/\[youtube\](.+?)\[\/youtube\]/is" ); $replace = array( "<iframe class=\"youtube-player\" width=\"100%\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen> </iframe>", "<img src=\"$1\" class=\"bbcodeimage-comment img-polaroid\" alt=\"[img]\" />", "<img width=\"$1\" height=\"$2\" src=\"$3\" class=\"bbcodeimage-comment img-polaroid\" alt=\"[img]\" />", "<iframe class=\"youtube-player\" width=\"550\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" data-youtube-id=\"$1\" frameborder=\"0\" allowfullscreen> </iframe>", // for xenforo videos "<iframe class=\"youtube-player\" width=\"550\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" data-youtube-id=\"$1\" frameborder=\"0\" allowfullscreen> </iframe>" ); $body = preg_replace($find, $replace, $body); } // get rid of empty BBCode, is there a point in having excess markup? $body = preg_replace("`\[(b|i|s|u|url|mail|img|quote|code|color|youtube)\]\[/(b|i|s|u|url|mail|img|quote|code|color|youtube)\]`",'',$body); $find = array( "/\[url\=(.+?)\](.+?)\[\/url\]/is", "/\[url\](.+?)\[\/url\]/is", "/\[b\](.+?)\[\/b\]/is", "/\[i\](.+?)\[\/i\]/is", "/\[u\](.+?)\[\/u\]/is", "/\[s\](.+?)\[\/s\]/is", "/\[color\=(.+?)\](.+?)\[\/color\]/is", "/\[font\=(.+?)\](.+?)\[\/font\]/is", "/\[center\](.+?)\[\/center\]/is", "/\[right\](.+?)\[\/right\]/is", "/\[left\](.+?)\[\/left\]/is", "/\[img\]http\:\/\/img\.youtube.com\/vi\/(.+?)\/0\.jpg\[\/img\]/is", //youtube videos done by the old tinymce plugin... "/\[img\](.+?)\[\/img\]/is", "/\[img=([0-9]+)x([0-9]+)\](.+?)\[\/img\]/is", "/\[email\](.+?)\[\/email\]/is", "/\[s\](.+?)\[\/s\]/is", "/\[media=youtube\](.+?)\[\/media\]/is", // This is for videos done by xenforo... "/\[youtube\](.+?)\[\/youtube\]/is", '/\[list\](.*?)\[\/list\]/is', '/\[\*\](.*?)(\n|\r\n?)/is', '/\[ul\]/is', '/\[\/ul\]/is', '/\[li\]/is', '/\[\/li\]/is', "/\[size\=(.+?)\](.+?)\[\/size\]/is", "/\[email\=(.+?)\](.+?)\[\/email\]/is", "/\[justify\](.+?)\[\/justify\]/is", "/\[code\](.+?)\[\/code\]/is", "/\[sup\](.+?)\[\/sup\]/is" ); $replace = array( "<a href=\"$1\" target=\"_blank\">$2</a>", "<a href=\"$1\" target=\"_blank\">$1</a>", "<strong>$1</strong>", "<em>$1</em>", "<span style=\"text-decoration:underline;\">$1</span>", "<del>$1</del>", "$2", "$2", "<div style=\"text-align:center;\">$1</div>", "<div style=\"text-align:right;\">$1</div>", "<div style=\"text-align:left;\">$1</div>", "<iframe class=\"youtube-player\" width=\"100%\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen> </iframe>", "<a class=\"fancybox\" rel=\"group\" href=\"$1\"><img src=\"$1\" class=\"bbcodeimage img-polaroid\" alt=\"[img]\" /></a>", "<a class=\"fancybox\" rel=\"group\" href=\"$3\"><img width=\"$1\" height=\"$2\" src=\"$3\" class=\"bbcodeimage img-polaroid\" alt=\"[img]\" /></a>", "<a href=\"mailto:$1\" target=\"_blank\">$1</a>", "<span style=\"text-decoration: line-through\">$1</span>", "<iframe class=\"youtube-player\" width=\"550\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" data-youtube-id=\"$1\" frameborder=\"0\" allowfullscreen> </iframe>", // for xenforo videos "<iframe class=\"youtube-player\" width=\"550\" height=\"385\" src=\"http://www.youtube.com/embed/$1\" data-youtube-id=\"$1\" frameborder=\"0\" allowfullscreen> </iframe>", '<ul>$1</ul>', '<li>$1</li>', '<ul>', '</ul>', '<li>', '</li>', '$2', '<a href="mailto:$1">$2</a>', '$1', 'Code:<br /><code>$1</code>', '<sup>$1</sup>' ); $smilies = array( ":><:" => '<img src="/includes/jscripts/sce/emoticons/angry.png" data-sceditor-emoticon=":><:" alt="" />', ":><:" => '<img src="/includes/jscripts/sce/emoticons/angry.png" data-sceditor-emoticon=":><:" alt="" />', // for comments as they are made html-safe ":'(" => '<img src="/includes/jscripts/sce/emoticons/cry.png" data-sceditor-emoticon=":\'(" alt="" />', // for comments as they are made html-safe ":'(" => '<img src="/includes/jscripts/sce/emoticons/cry.png" data-sceditor-emoticon=":'(" alt="" />', ":dizzy:" => '<img src="/includes/jscripts/sce/emoticons/dizzy.png" data-sceditor-emoticon=":dizzy:" alt="" />', ":D" => '<img src="/includes/jscripts/sce/emoticons/grin.png" data-sceditor-emoticon=":D" alt="" />', "^_^" => '<img src="/includes/jscripts/sce/emoticons/happy.png" data-sceditor-emoticon="^_^" alt="" />', "<3" => '<img src="/includes/jscripts/sce/emoticons/heart.png" data-sceditor-emoticon="<3" alt="" />', "<3" => '<img src="/includes/jscripts/sce/emoticons/heart.png" data-sceditor-emoticon="<3" alt="" />', // for comments as they are made html-safe ":huh:" => '<img src="/includes/jscripts/sce/emoticons/huh.png" data-sceditor-emoticon=":huh:" alt="" />', ":|" => '<img src="/includes/jscripts/sce/emoticons/pouty.png" data-sceditor-emoticon=":|" alt="" />', ":(" => '<img src="/includes/jscripts/sce/emoticons/sad.png" data-sceditor-emoticon=":(" alt=""/>', ":O" => '<img src="/includes/jscripts/sce/emoticons/shocked.png" data-sceditor-emoticon=":O" alt="" />', ":sick:" => '<img src="/includes/jscripts/sce/emoticons/sick.png" data-sceditor-emoticon=":sick:" alt="" />', ":)" => '<img src="/includes/jscripts/sce/emoticons/smile.png" data-sceditor-emoticon=":)" alt="" />', ":P" => '<img src="/includes/jscripts/sce/emoticons/tongue.png" data-sceditor-emoticon=":P" alt="" />', ":S:" => '<img src="/includes/jscripts/sce/emoticons/unsure.png" data-sceditor-emoticon=":S" alt="" />', ":woot:" => '<img src="/includes/jscripts/sce/emoticons/w00t.png" data-sceditor-emoticon=":woot:" alt="" />', ":whistle:" => '<img src="/includes/jscripts/sce/emoticons/whistle.png" data-sceditor-emoticon=":whistle:" alt="" />', ";)" => '<img src="/includes/jscripts/sce/emoticons/wink.png" data-sceditor-emoticon=";)" alt="" />', ":wub:" => '<img src="/includes/jscripts/sce/emoticons/wub.png" data-sceditor-emoticon=":wub:" alt="" />' ); $body = str_replace( array_keys( $smilies ), array_values( $smilies ), $body ); $body = preg_replace($find, $replace, $body); $body = nl2br($body); // stop there being a big gap between list items $body = str_replace('</li><br />', '</li>', $body); // stop there being a big gap after a list is finished $body = str_replace('</ul><br />', '</ul>', $body); // stop big gaps after embedding a tweet from twitter $body = str_replace('</a></blockquote><br />', '</a></blockquote>', $body); $body = str_replace('</script><br />', '</script>', $body); return $body; } Completely stuck on how I can achieve this