portalzine / Extract text between two tags (domDocument)
0 likes
0 forks
1 files
Last active 7 months ago
| 1 | $tag = "p"; |
| 2 | $html ="I am here!"; |
| 3 | $dom = new domDocument('1.0', 'utf-8'); |
| 4 | $dom->loadHTML($html); |
| 5 | $dom->preserveWhiteSpace = false; |
| 6 | |
| 7 | $findTag = $dom->getElementsByTagName($tag); |
| 8 | |
| 9 | echo $findTag->item(0)->nodeValue; |
portalzine / Syntax Highlighting Class
0 likes
0 forks
2 files
Last active 7 months ago
| 1 | class SyntaxHighlight { |
| 2 | |
| 3 | static $tokens = array();// This array will be filled from the regexp-callback |
| 4 | public static function process($s) { |
| 5 | $s = htmlspecialchars($s); |
| 6 | // Workaround for escaped backslashes |
| 7 | $s = str_replace('\\\\','\\\\<e>', $s); |
| 8 | $regexp = array( |
| 9 | // Punctuations |
| 10 | '/([\-\!\%\^\*\(\)\+\|\~\=\`\{\}\[\]\:\"\'<>\?\,\.\/]+)/' |
Newer
Older