Dukungan Markup
Mendukung hampir semua markup seperti yang dinyatakan dalam dokumentasi Markdown Extra, kecuali markup catatan kaki, abbreviasi, daftar definisi, tautan ber–referensi dan gambar ber–referensi.
Mendukung hampir semua markup seperti yang dinyatakan dalam dokumentasi Markdown Extra, kecuali markup catatan kaki, abbreviasi, daftar definisi, tautan ber–referensi dan gambar ber–referensi.
function get_first_image_url($data, $default_url = null) {
/**
* Matched with ...
* ----------------
*
* [1]. ``
* [2]. ``
*
* ... and the single-quoted version of them
*
*/
if(preg_match_all('#\!\[.*?\]\(([^\s]+?)( +([\'"]).*?\3)?\)#', $data, $matches)) {
return $matches[1][0];
}
/**
* Matched with ...
* ----------------
*
* [1]. `<img src="IMAGE URL">`
* [2]. `<img foo="bar" src="IMAGE URL">`
* [3]. `<img src="IMAGE URL" foo="bar">`
* [4]. `<img src="IMAGE URL"/>`
* [5]. `<img foo="bar" src="IMAGE URL"/>`
* [6]. `<img src="IMAGE URL" foo="bar"/>`
* [7]. `<img src="IMAGE URL" />`
* [8]. `<img foo="bar" src="IMAGE URL" />`
* [9]. `<img src="IMAGE URL" foo="bar" />`
*
* ... and the uppercased version of them, and the single-quoted version of them
*
*/
if(preg_match_all('#<img .*?src=([\'"])([^\'"]+?)\1.*? *\/?>#i', $data, $matches)) {
return $matches[2][0];
}
return $default_url; // Default image URL if nothing matched
}<img src="<?php echo get_first_image_url($page['content'], 'img/no-image.png'); ?>">$page['content'] cuma contoh. Anda harus mengambilnya dari konten posting Anda sesuai dengan API pada CMS yang Anda pakai.
function getFirstImageURL(data, noImage) {
/**
* Matched with ...
* ----------------
*
* [1]. ``
* [2]. ``
*
* ... and the single-quoted version of them
*
*/
var matches = /\!\[.*?\]\(([^\s]+?)( +[\'"].*?[\'"])?\)/.exec(data);
return matches ? matches[1] : noImage;
/**
* Matched with ...
* ----------------
*
* [1]. `<img src="IMAGE URL">`
* [2]. `<img foo="bar" src="IMAGE URL">`
* [3]. `<img src="IMAGE URL" foo="bar">`
* [4]. `<img src="IMAGE URL"/>`
* [5]. `<img foo="bar" src="IMAGE URL"/>`
* [6]. `<img src="IMAGE URL" foo="bar"/>`
* [7]. `<img src="IMAGE URL" />`
* [8]. `<img foo="bar" src="IMAGE URL" />`
* [9]. `<img src="IMAGE URL" foo="bar" />`
*
* ... and the uppercased version of them, and the single-quoted version of them
*
*/
matches = /<img .*?src=[\'"]([^\'"]+?)[\'"].*? *\/?>/i.exec(data);
return matches ? matches[1] : noImage;
}var img = '<img src="' + getFirstImageURL(sourceText, 'img/no-image.png') + '">';
document.write(img);sourceText cuma contoh. Anda harus mengambilnya dari konten posting Anda, misalnya dengan cara ini:
var sourceText = document.querySelector('.post-body').innerHTML;
<("[^"]*"|'[^']*'|[^'">])*>Cocok untuk pola ini:
<input value='>'><input value='<'><a href="http://www.nama_web.com"><br>, <br/><input value="'" id="test">, <input value='"' id='test'>Fungsi ini digunakan untuk mengubah deret angka menjadi pola mata uang dimana setiap tiga deret angka akan ditambahi sebuah titik atau koma setelahnya/sebelumnya, dimulai dari belakang:
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}addCommas('10000000'); // Hasil => 10,000,000