Highlight HTML en XML

Door Martijn Wieringa, 21 jaar geleden, 4.952x bekeken

n.a.v. de highlight SQL functie heb ik nu ook een highlight HTML functie gebouwd.

Op en aanmerkingen zijn wederom erg welkom!

Enjoy!

Voorbeeld: http://www.pholeron.nl/projects/highlight_html/

Gesponsorde koppelingen

PHP script bestanden

  1. highlight-html-en-xml

 

Er zijn 15 reacties op 'Highlight html en xml'

PHP hulp
PHP hulp
0 seconden vanaf nu
 

Gesponsorde koppelingen
GaMer B
GaMer B
21 jaar geleden
 
0 +1 -0 -1
Wederom een erg goed scriptje, net als SQL highlight! *Thumbs-up*
Robert Deiman
Robert Deiman
21 jaar geleden
 
0 +1 -0 -1
Mooi werk Pholeron leuk gedaan.

Offtopic:

Nu de SQL, PHP, CSS en HTML nog combineren zodat je heel mooi de inhoud van een pagina overzichtelijk weer kan geven. (En er dan wel rekening mee houden dat HTML in PHP niet wordt verwerkt ;))
Martijn Wieringa
Martijn Wieringa
21 jaar geleden
 
0 +1 -0 -1
Ik ben al bezig met een UBBparser die straks html, sql, php, css, javascript, smileys e.d. moet ondersteunen.. :P
Martijn Wieringa
Martijn Wieringa
21 jaar geleden
 
0 +1 -0 -1
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php

    // Parse UBB code to HTML
    function ubbToHtml($string, $bAddDefaultCss = false)
    {

        $result = '';

        // Slice string into UBB blocks
        $expr = '/(\[((\n|.)*?)\]((\n|.)*?)\[\/\\2\])|(&lt;\?((\n|.)*?)\?&gt;)|(.)/i';
        preg_match_all($expr, $string, $matches);

        for($i = 0; $i < sizeof($matches[0]); $i++)
        {

            if(strcasecmp($match = $matches[0][$i], "") !== 0)
            {

                if(preg_match('/\[code\]((\n|.)*?)\[\/code\]/i', $match)) // General code block
                {
                    $result .= '<code>' . stringToHtml(trim(substr($match, 6, -7))) . '</code>';
                }

                elseif(preg_match('/\[css\]((\n|.)*?)\[\/css\]/i', $match)) // HTML
                {
                    $result .= highlight_css(trim(substr($match, 6, -7)), $bAddDefaultCss);
                }

                elseif(preg_match('/\[html\]((\n|.)*?)\[\/html\]/i', $match)) // HTML
                {
                    $result .= highlight_html(trim(substr($match, 6, -7)), $bAddDefaultCss);
                }

                elseif(preg_match('/\[js\]((\n|.)*?)\[\/js\]/i', $match)) // Javascript
                {
                    $result .= highlight_js(trim(substr($match, 4, -5)), $bAddDefaultCss);
                }

                elseif(preg_match('/\[php\]((\n|.)*?)\[\/php\]/i', $match)) // PHP
                {
                    $result .= highlight_php(trim(substr($match, 5, -6)), $bAddDefaultCss);
                }

                elseif(preg_match('/\[sql\]((\n|.)*?)\[\/sql]/i', $match)) // SQL
                {
                    $result .= highlight_sql(trim(substr($match, 5, -6)), $bAddDefaultCss);
                }

                elseif(preg_match('/\[vb\]((\n|.)*?)\[\/js\]/i', $match)) // Visual Basic
                {
                    $result .= highlight_vb(trim(substr($match, 4, -5)));
                }

                elseif(preg_match('/\[xml\]((\n|.)*?)\[\/js\]/i', $match)) // XML
                {
                    $result .= highlight_xml(trim(substr($match, 5, -6)), $bAddDefaultCss);
                }

                elseif(preg_match('/\[quote\]((\n|.)*?)\[\/quote\]/i', $match)) // Some quote
                {
                    $result .= '<blockquote>' . stringToHtml(trim(substr($match, 7, -8))) . '</blockquote>';
                }

                else // Inline tags
                {
                    // Escape HTML syntax
                    $match = stringToHtml($match);

                    // Bold
                    $match = preg_replace('/\[b\]((\n|.)*?)\[\/b\]/i', '<b>\\1</b>', $match);
                    $match = preg_replace('/\[bold\]((\n|.)*?)\[\/bold\]/i', '<b>\\1</b>', $match);

                    // Italic
                    $match = preg_replace('/\[i\]((\n|.)*?)\[\/i\]/i', '<i>\\1</i>', $match);
                    $match = preg_replace('/\[italic\]((\n|.)*?)\[\/italic\]/i', '<i>\\1</i>', $match);

                    // Underline
                    $match = preg_replace('/\[u\]((\n|.)*?)\[\/u\]/i', '<u>\\1</u>', $match);
                    $match = preg_replace('/\[underline\]((\n|.)*?)\[\/underline\]/i', '<u>\\1</u>', $match);

                    // Strike
                    $match = preg_replace('/\[s\]((\n|.)*?)\[\/s\]/i', '<strike>\\1</strike>', $match);
                    $match = preg_replace('/\[strike\]((\n|.)*?)\[\/strike\]/i', '<strike>\\1</strike>', $match);

                    // Sup
                    $match = preg_replace('/\[sup\]((\n|.)*?)\[\/sup\]/i', '<sup>\\1</sup>', $match);

                    // Sub
                    $match = preg_replace('/\[sub\]((\n|.)*?)\[\/sub\]/i', '<sub>\\1</sub>', $match);

                    // Color
                    $match = preg_replace('/\[color=&quot;(.*?)&quot;\]((\n|.)*?)\[\/color\]/i', '<span style="color: \\1;">\\2</span>', $match);
                    $match = preg_replace('/\[color=(.*?)\]((\n|.)*?)\[\/color\]/i', '<span style="color: \\1;">\\2</span>', $match);

                    // Google link
                    $match = preg_replace('/\[google\]((\n|.)*?)\[\/google\]/i', '<a href="http://www.google.nl/search?q=\\1" target="_new">\\1</a>', $match);

                    // Image
                    $match = preg_replace('/\[img align=&quot;(.*?)&quot;\](.*?)\[\/img\]/i', '<img align="\\1" alt="\\2" border="0" src="\\2">', $match);
                    $match = preg_replace('/\[img align=(.*?)\](.*?)\[\/img\]/i', '<img align="\\1" alt="\\2" border="0" src="\\2">', $match);
                    $match = preg_replace('/\[img\](.*?)\[\/img\]/i', '<img alt="\\1" border="0" src="\\1">', $match);
                    $match = preg_replace('/\[image align=&quot;(.*?)&quot;\](.*?)\[\/image\]/i', '<img align="\\1" alt="\\2" border="0" src="\\2">', $match);
                    $match = preg_replace('/\[image align=(.*?)\](.*?)\[\/image\]/i', '<img align="\\1" alt="\\2" border="0" src="\\2">', $match);
                    $match = preg_replace('/\[image\](.*?)\[\/image\]/i', '<img alt="\\1" border="0" src="\\1">', $match);

                    // Parse URLs
                    $match = preg_replace('/\[url=&quot;(.*?)&quot;\](.*?)\[\/url\]/i', '<a href="\\1" target="_new">\\2</a>', $match); // [url="http://www.domain.tld"]label[/url]
                    $match = preg_replace('/\[url=(.*?)\](.*?)\[\/url\]/i', '<a href="\\1" target="_new">\\2</a>', $match); // [url=http://www.domain.tld]label[/url]
                    $match = preg_replace('/\[url\](.*?)\[\/url\]/i', '<a href="\\1" target="_new">\\1</a>', $match); // [url]http://www.domain.tld[/url]

                    $result .= $match;
                }
            }
        }


        return $result;
    }


?>


.. alleen zijn de meeste highlight_???() nog niet goed genoeg uitgewerkt ;)

maar als ie af is wordt ie hier natuurlijk ook gepost!
Marvin S
Marvin S
21 jaar geleden
 
0 +1 -0 -1
Je maakt erg mooie en vooral nuttige scripts..
Dit soort scripts vind ik erg handig als ik bijvoorbeeld
ergens achter een pc zit zonder php/html editor..
dan is dit veel makkelijker foutzoeken als in kladblok
netjes netjes netjes

Keep going
GaMer B
GaMer B
21 jaar geleden
 
0 +1 -0 -1
Dat wordt geweldig als je een "alles-in-een" parser maakt. Nice work.
Yordi B
Yordi B
21 jaar geleden
 
0 +1 -0 -1
als je alles samenvoegt heb je een hele mooie webeditor alleen regelnummering nog :P
- -
- -
21 jaar geleden
 
0 +1 -0 -1
Mooi script!


21 jaar geleden
 
0 +1 -0 -1
Ziet er weer geweldig uit.
Vroeger had ik er ergens een die een stuk of 30 talen kon highliten,... maar waar die stond
Leroy Boerefijn
Leroy Boerefijn
21 jaar geleden
 
0 +1 -0 -1
stoer :)

alleen de doctype is niet gekleurd ;)
Marien xD
Marien xD
21 jaar geleden
 
0 +1 -0 -1
Ja maak de doctype even bijv grijs gehighlite!
Joeri
Joeri
21 jaar geleden
 
0 +1 -0 -1
Schitterend, doe zeker zo voort!! Eindelijk nog eens originaliteit en mooi scripting! Streepje voor zou ik zo zeggen.

Zeker posten als je Parser af is zou ik zeggen.
The Hosh
The Hosh
21 jaar geleden
 
0 +1 -0 -1
cool..
maar hoe zorg je er voor dat het php, script en style overslaat?
Legolas
Legolas
21 jaar geleden
 
0 +1 -0 -1
@Webmakerij: GeSHi (dat is de bekendste, die is er ook voor phpBB, MediaWiki, Joomla etc etc)
PHP hulp
PHP hulp
0 seconden vanaf nu
 

Gesponsorde koppelingen
Jesper Diovo
Jesper Diovo
18 jaar geleden
 
0 +1 -0 -1
Waarom wordt mijn "<form method="post">" niet gehighlight?

Om te reageren heb je een account nodig en je moet ingelogd zijn.

Inhoudsopgave

  1. highlight-html-en-xml

Labels

  • Geen tags toegevoegd.

Navigatie

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.