eval.in

Paste #668661

PHP — PHP 7.0.8, pasted 1 year ago (json)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?php


$data   = "Bor ekan * / 2002*\nBaxt bo'ladi * / 2004*\nBaxtliman * / 2005*\nBu mening tanlovim * / 2005*\nRadio tinglamayman * / 2005*\nYana albomlar * / 2005*\nYana bitta uzun * / 2005*\nYangi yil albomi * / 2005*\nEng yaxshi * / 2005*\nBa'zi  qo'shiqlar * / 2005*\nKo'p yuklab olingan * / 2005*\nYevropa hitlari * / 2005*\n";
function transformData($data){
	$output         = '';
	if(is_string($data)){
		$data           = explode('\n', $data);
	}

	foreach($data as $val){
		$extract    = preg_replace("#(.*?)\*(.*?)\*#", "<li>$1<span class='disk-year'>$2</span></li>", $val);
		$output    .= $extract . PHP_EOL;
	}

	return $output;
}

var_dump(transformData($data));

Program Output

string(759) "<li>Bor ekan <span class='disk-year'> / 2002</span></li>
<li>Baxt bo'ladi <span class='disk-year'> / 2004</span></li>
<li>Baxtliman <span class='disk-year'> / 2005</span></li>
<li>Bu mening tanlovim <span class='disk-year'> / 2005</span></li>
<li>Radio tinglamayman <span class='disk-year'> / 2005</span></li>
<li>Yana albomlar <span class='disk-year'> / 2005</span></li>
<li>Yana bitta uzun <span class='disk-year'> / 2005</span></li>
<li>Yangi yil albomi <span class='disk-year'> / 2005</span></li>
<li>Eng yaxshi <span class='disk-year'> / 2005</span></li>
<li>Ba'zi  qo'shiqlar <span class='disk-year'> / 2005</span></li>
<li>Ko'p yuklab olingan <span class='disk-year'> / 2005</span></li>
<li>Yevropa hitlari <span class='disk-year'> / 2005</span></li>

"

OK (0.008 sec real, 0.008 sec wall, 16 MB, 49 syscalls)

Fork