Jump to content

thebadbad

Members
  • Posts

    1,613
  • Joined

  • Last visited

Everything posted by thebadbad

  1. Yeah, should've thought of that I know this, but I tend to always escape literal square brackets, to make it less confusing for less experienced regex'ers.
  2. FYI, preg_match_all() returns the number of full pattern matches.
  3. If you're searching for a plain string, use strpos() or stripos() for case insensitivity: <?php if (strpos($var, 'srv_9 (Dead ???)') !== false) { echo '$var contains the searched string.'; } ?>
  4. Something like <?php preg_match_all('~\bsrc\s?=\s?([\'"])(http://.+?)\1~is', $value, $matches); foreach ($matches[2] as $url) { if (strpos($url, 'pass') !== false) { echo "Match found: $url"; break; } } ?> You can use stripos() if the search should be case insensitive.
  5. Just a small note; you can remove the optional capture since the word boundary will match even if the following character class (quantized with the asterisk) matches zero times. '~<b\b[^>]*>~i'
  6. My approach: <?php $str = 'Text with a linebreak [code=test]test test test test2 test2 test2 test2 '; $str = preg_replace_callback( '~(\ [code[^\]]*\])(.*?)(\[/code\])~is', create_function( '$matches', 'return $matches[1] . str_replace(array("\r\n", "\r", "\n"), \'<br />\', $matches[2]) . $matches[3];' ), $str ); //run your bbcode function here, including nl2br() echo $str; ?>[/code]
  7. Add is after the last ~ to make the search case insensitive and to make the dot match line breaks. If it also should remove empty quote tags like , use an asterisk instead of the plus. ~\[quote\].*?\[/quote\]~is
  8. You can use something like <?php $str = 'djk44jkasd32sd'; $parts = preg_split('~([0-9]+)~', $str, null, PREG_SPLIT_DELIM_CAPTURE); echo '<pre>' . print_r($parts, true) . '</pre>'; ?>
  9. I would do something like this: <?php $str = '<a href="test.php">test</a> <br /> [nohtml] <a href="test2.php">test2</a> [/nohtml]'; $str = preg_replace_callback( '~\[nohtml\](.*?)\[nohtml\]~is', create_function( '$matches', 'return htmlentities($matches[1], ENT_QUOTES);' ), $str ); echo $str; ?> preg_replace_callback() @ the manual.
  10. You can quite easily support nested tags by dealing with the opening and closing tags separately. Relevant posts: http://www.phpfreaks.com/forums/index.php/topic,205904.msg934306.html#msg934306 and http://www.phpfreaks.com/forums/index.php/topic,266663.msg1259603.html#msg1259603 (seeing if the tags match up)
  11. Can't see why this shouldn't work: <?php if (isset($_GET['url'])) { $converter = array( 'blankspot' => 'blanks', 'soccer' => '906', 'blankspothere' => 'blank' ); $url = $_GET['url']; if (isset($converter[$url])) { $xml = @simplexml_load_file('/flv_player/data/playerConfigEmbed/' . $converter[$url] . '.xml'); if ($xml) { echo (string) $xml->media->content->video['SD']; exit; } } } header('Location: http://www.sqweasel.com/'); ?>
  12. No it doesn't. But for some reason it escapes the quotes. When I use this instead, it doesn't: preg_replace('~(<pre\b[^>]*>)(.*?)(</pre>)~ise', '"$1" . htmlentities("$2") . "$3"', $my_text);
  13. Yep, just add the s modifier after the pattern (I also added a word boundary and made the search case insensitive): preg_replace('~<pre\b[^>]*>(.*?)</pre>~ise', 'htmlentities(\'$1\')', $my_text); If you want to retain the pre tags around the matched content, just grab the tags and use them in the replacement: preg_replace('~(<pre\b[^>]*>)(.*?)(</pre>)~ise', '\'$1\' . htmlentities(\'$2\') . \'$3\'', $my_text); I'm grabbing the last match to be sure the casing is right. Guess it's not necessary though.
  14. Absolutely right. But why ask when you can try it out in like 1 sec?
  15. In your sample code you're using $path before you've set it?
  16. Could also have something to do with the character encoding. If you post a file including a sample string with the odd characters, we can test your code and see our results.
  17. Could be done with a database and AJAX. Or without AJAX, if you can live with it reloading the page on submit.
  18. 1. No. 2. If your apostrophes are represented with HTML entities, that's where your problem lies. When you output your sample string, check the source code of it, and see if you find any HTML entities. If you do, you can simply replace them with something like $str = str_replace('&#39;', "'", $str); or by using html_entity_decode(), but that will convert all HTML entities to the characters they represent.
  19. Lol, I was about to post this, but then you beat me to it, haha:
  20. thebadbad

    Timer

    So have you considered using sleep() within your loop?
  21. Those are just the pattern delimiters of my preference. They can be any non-white space, non-alphanumeric ASCII character (except a backslash). And it's always smart to use delimiters that don't appear within the pattern, so you don't have to escape them, hence my use of the 'odd' tildes (I have yet to write a pattern matching a tilde). When you're using forward slashes as pattern delimiters, you would have to escape any forward slashes inside the pattern - something that occurs quite often.
  22. Edited your patterns a bit: $text = preg_replace('~\S+@\S+\.[a-z]+~i', '<a href="mailto:$0">$0</a>', $text); $text = preg_replace('~(^|\s)@([a-z0-9_]+)~i', '$1@<a href="http://twitter.com/$2" target="_blank">$2</a>', $text); The email one being this simple will also convert invalid emails, but it should at least work properly now.
  23. Try something like <?php if (preg_match('~MSIE ([^;]+);~', $_SERVER['HTTP_USER_AGENT'], $match)) { echo 'Internet Explorer version: ' . htmlentities($match[1]); } else { echo 'Browser isn\'t Internet Explorer'; } ?> I'm using htmlentities() because the user agent string can be spoofed by the user, potentially containing malicious code to be executed.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.