Jump to content

thebadbad

Members
  • Posts

    1,613
  • Joined

  • Last visited

About thebadbad

  • Birthday 10/29/1988

Profile Information

  • Gender
    Male
  • Location
    Denmark

thebadbad's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Algorithms in the SHA-2 family are recommended by NIST. Remember that your salt should be a random string with at least as many variable bits, as there are bits in the hash result. Then you're good to go!
  2. He's not looking to accept alphanumeric characters only:
  3. As long as you encode the text with htmlentities() or similar, it should be valid.
  4. The way I would go about it: $img = preg_replace('~<img\b[^>]*\bsrc\s?=\s?([\'"])cid:[^\1]*\1[^>]*>~i', '', $img);
  5. preg_match('~\$Revision: (\S+)~', $this->revision, $rev); \S is a shorthand character class matching any non-whitespace character. The only other difference is the use of pattern delimiters (tildes in my case), which is required with preg_match().
  6. Or if you want to use the external page's title (if applicable): function _callback($matches) { $html = file_get_contents($matches[0]); if ($html != false) { if (preg_match('~<title\b[^>]*>(.+?)</title>~is', $html, $match)) { return '<a href="' . $matches[0] . '">' . $match[1] . '</a>'; } } return '<a href="' . $matches[0] . '">' . parse_url($matches[0], PHP_URL_HOST) . '</a>'; } $ret = preg_replace_callback('~\bhttp://\S+(?![^<]*?>)~i', '_callback', $ret);
  7. Quick example: function _callback($matches) { return '<a href="' . $matches[0] . '">' . parse_url($matches[0], PHP_URL_HOST) . '</a>'; } $ret = preg_replace_callback('~\bhttp://\S+(?![^<]*?>)~i', '_callback', $ret);
  8. One way you can do it, although it's not very elegant: $content = 'Testing a test with this! Tag: <span title="test">tag</span>. <h1>Test heading</h1>'; //replace keywords (that are not part of HTML tags) $content = preg_replace('~\btest\b(?![^<]*?>)~i', '<a href="" UNIQUE>$0</a>', $content); //remove created links between heading tags function _callback($matches) { return preg_replace('~<a href="[^"]*" UNIQUE>(.*?)</a>~s', '$1', $matches[0]); } $content = preg_replace_callback('~<h([1-6])\b[^>]*>.+?</h\1>~is', '_callback', $content); //remove UNIQUE marks $content = preg_replace('~(<a href="[^"]*") UNIQUE>~', '$1>', $content); header('Content-type: text/plain; charset=utf-8'); echo $content;
  9. You should be able to use get_meta_tags() for the META tags (else the comments on that page also contains regex solutions). You can check for iframes with this: //$html contains page source code if (preg_match_all('~<iframe\b[^>]+src\s?=\s?([\'"])(.+?)\1[^>]*>~is', $html, $matches)) { echo '<pre>' . print_r($matches[2], true) . '</pre>'; } else { echo 'No iframes found.'; }
  10. ctype_digit() will strictly check for numbers (in a string) only.
  11. The fastest way to check if it begins with 202. is using substr(): if (substr($remoteaddr, 0, 4) == '202.') { //... } The regex approach could be if (preg_match('~^202\.~', $remoteaddr)) { //... }
  12. $str = ' <h2 style="color: #383737; margin-bottom: 3px; text-transform: capitalize;">Details</h2><br/> <h2>input</h2><br/>'; preg_match('~>Details</h2><br/>\s*<h2>(.*?)</h2><br/>~is', $str, $match); echo $match[1]; \s* matches zero or more whitespace characters (including line breaks).
  13. When you're just replacing simple text, you can achieve this effect with strtr(). But I'm not sure how to get it done with regular expressions involved. $str = 'this string contains this body of text and works for an example'; $replace = array( 'this body of text' => '<span class="highlight">this body of text</span>', 'this body' => '<span class="highlight">this body</span>', 'body of text' => '<span class="highlight">body of text</span>', 'body' => '<span class="highlight">body</span>' ); echo strtr($str, $replace); //this string contains <span class="highlight">this body of text</span> and works for an example
  14. No worries. In that case you can define an array of patterns and replacements: $replace = array( '~\[\[#([0-9]+)#\]\](.*?)\[\[end\]\]~is' => '<a href="javascript:;" onclick="Show_Stuff(\'$1\');">Show</a> <div style="display:none;" id="$1">$2</div><br />', '~\[\*(.*?)\*\]~s' => '<strong>$1</strong>', '#\[~(.*?)~\]#s' => '<em>$1</em>' ); $str = preg_replace(array_keys($replace), $replace, $str); I used strong and em tags since the b and i tags are deprecated.
  15. I would just go with a simple <?php $str = '[[#201001251351#]]Some text here[[end]] Something else in this bit [[#201001251353#]]Some different text here[[end]] And more different bits [[#201001251357#]]Some more here[[end]] Further different bits which may include other replaced things'; $replace = '<a href="javascript:;" onclick="Show_Stuff(\'$1\');">Show</a> <div style="display:none;" id="$1">$2</div><br />'; echo preg_replace('~\[\[#([0-9]+)#\]\](.*?)\[\[end\]\]~is', $replace, $str); ?>
×
×
  • 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.