Pages

Thursday, December 1, 2016

Menulis Script Program pada Website PHP dengan Syntaxhighlighter

Seperti yang kita ketahui, menulis posting yang berisi sintaks program memang harus di bedakan dengan teks biasa. Karena sintaks program mempunyai banyak tag atau tanda-tanda yang harus diperhatikan dalam menulis bahasa program, salah satunya dengan menggunakan Syntaxhighlighter seperti yang terihat dibawah ini.

Untuk bisa membuat syntaxhighlighter, anda harus download file di link ini. 
Lalu buat file html dengan koding dibawah ini.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" rel="stylesheet" href="syntaxhl/js/syntaxhighlighter/styles/shCoreDefault.css"/>
<link type="text/css" rel="stylesheet" href="syntaxhl/js/syntaxhighlighter/styles/shCoreMidnight.css" />
<link type="text/css" rel="stylesheet" href="syntaxhl/js/syntaxhighlighter/styles/shThemeMidnight.css" />  
<script type="text/javascript" src="syntaxhl/js/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="syntaxhl/js/syntaxhighlighter/scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="syntaxhl/js/syntaxhighlighter/scripts/shBrushPhp.js"></script>
<script type="text/javascript" src="syntaxhl/js/syntaxhighlighter/scripts/shBrushPlain.js"></script>
<script type="text/javascript" src="syntaxhl/js/syntaxhighlighter/scripts/shBrushSql.js"></script>
<script type="text/javascript" src="syntaxhl/js/syntaxhighlighter/scripts/shBrushXml.js"></script>
<script type="text/javascript">
 SyntaxHighlighter.all();
</script>
    </head>
<div class="konten">
  
</div>
</html>

Parse script yang akan ditampilkan. sebagai contoh script berikut sudah di parse.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
&lt;form action=&quot;cari_act.php&quot; method=&quot;get&quot;&gt;
 &lt;div class=&quot;input-group col-md-5 col-md-offset-7&quot;&gt;
  &lt;span class=&quot;input-group-addon&quot; id=&quot;basic-addon1&quot;&gt;&lt;span class=&quot;glyphicon glyphicon-search&quot;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Search ...&quot; aria-describedby=&quot;basic-addon1&quot; name=&quot;cari&quot;&gt;
 &lt;/div&gt;
&lt;/form&gt;
&lt;br/&gt;
&lt;table class=&quot;table table-hover&quot;&gt;
 &lt;tr&gt;
  &lt;th class=&quot;col-md-1&quot;&gt;No&lt;/th&gt;
  &lt;th class=&quot;col-md-2&quot;&gt;Kelurahan&lt;/th&gt;
  &lt;th class=&quot;col-md-3&quot;&gt;Dari Jam&lt;/th&gt;
  &lt;th class=&quot;col-md-3&quot;&gt;Sampai Jam&lt;/th&gt;
        &lt;th class=&quot;col-md-1&quot;&gt;Notice&lt;/th&gt;
        &lt;th class=&quot;col-md-2&quot;&gt;Opsi&lt;/th&gt;
 &lt;/tr&gt;

Letakkan kode tersebut di dalam tag div class konten.
1
2
3
4
5
<div class="konten">
 <pre class="brush:js; brush:php; brush:xml; ">
  //Letakkan disini kode yang sudah di parse
 </pre>
</div>

Maka akan menjadi sebagai berikut.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<pre class="brush:js; brush:php; brush:xml;">
&lt;form action=&quot;cari_act.php&quot; method=&quot;get&quot;&gt;
 &lt;div class=&quot;input-group col-md-5 col-md-offset-7&quot;&gt;
  &lt;span class=&quot;input-group-addon&quot; id=&quot;basic-addon1&quot;&gt;&lt;span class=&quot;glyphicon glyphicon-search&quot;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Search ...&quot; aria-describedby=&quot;basic-addon1&quot; name=&quot;cari&quot;&gt;
 &lt;/div&gt;
&lt;/form&gt;
&lt;br/&gt;
&lt;table class=&quot;table table-hover&quot;&gt;
 &lt;tr&gt;
  &lt;th class=&quot;col-md-1&quot;&gt;No&lt;/th&gt;
  &lt;th class=&quot;col-md-2&quot;&gt;Kelurahan&lt;/th&gt;
  &lt;th class=&quot;col-md-3&quot;&gt;Dari Jam&lt;/th&gt;
  &lt;th class=&quot;col-md-3&quot;&gt;Sampai Jam&lt;/th&gt;
        &lt;th class=&quot;col-md-1&quot;&gt;Notice&lt;/th&gt;
        &lt;th class=&quot;col-md-2&quot;&gt;Opsi&lt;/th&gt;
 &lt;/tr&gt;
</pre>

Setelah selesai, lihat hasilnya, pastikan semuanya tidak ada error.

No comments:

Post a Comment