Jump to content
php.lv forumi

[img1] to <img> tag


element

Recommended Posts

varbuut kaadam ir idejas kur shajaa f-jaa ir probleema, jo vinjai drausmiigi nepatiik, kad masiivaa es ielaadeeju atpakalj jau sagatavotu tagu (varbuut ir idejas kaa to savaadaak vareetu paveikt?):

 

function change_str2pic($str,$aid) {

$array = explode(" ",$str);

foreach ($array as $word) {

if (ereg("^([)+(img[0-9])+(])$", $word)) {

//echo "str atbilst [img22]";

$ima = substr($word, 4); //saakam ar naakosho charu aiz [img

$ima = str_replace("]", "", $ima); //beigaas novaacam ]

//$word="<img scr='images/article/".$article_id."_".$ima.".jpg'/>";

$word="<img scr='images/article/".$aid."_".$ima.".jpg'>";

}

$newarray[] = $word;

$str = implode(" ",$newarray);

}

//print_r($newarray);

return $str;

}

Edited by element
Link to comment
Share on other sites

nu ja, paarbaudu stringu pirms un peec funkcijas.. taatad probleema ir kur citur? wtf?

nav skaidrs kaapeec tieshi tagus vinjsh masiivaa man atpakalj nesaliek.. jo:

sanjemam stringu, kuru sadalam masiivaa pa vaardiem ar atstarpeem un skatamies vai kaads no stringiem satur (cipars) liidz ar to img sanjem cipara veertiibu, kuru peectam izmanto img scr un tad elementaari saliek visu atpakalj vienaa mainiigajaa ar atstarpeem

Edited by element
Link to comment
Share on other sites

es laikam kautko tomeer nesaprotu, jo mana funkcija izvada nepareizus datus, atstaajot masiiva pirmo elementu tukshu, kur vajadzeeja buut bildes tagam

uz ff vispaar bilde neparaadaas, bet uz ie paraadaas taa it kaa bildes scr nebuutu pareizi noraadiits un taatad

blaq [img1] blag

Array ( [0] => blaq [1] => [2] => blag [3] => ) blaq blag

shaadi man izskataas jaunais masiivs. kur vareetu buut probleema? :(

 

nja, neuzmaniibas kljuuda - src pareizi ir. paldies par paliidziibu eniivei ;)

Edited by element
Link to comment
Share on other sites

  • 2 weeks later...

kaa iespeejams sho uzrakstiit ar preg_replace, nesadalot masiivaa.. varbuut Jums ir kaadas idejas?

patreizeejaa funkcija izdomaa dazhos gadiijumos tomeer izdot atpakalj to tagu [img1] (piemeeram), nepaarveidojot par <img>

function change_str2pic($str,$aid,$nrpk,$type) {
$array = explode(" ",$str);
foreach ($array as $word) {
  if (ereg("^([)+(img[0-9])+(])$", $word)) {
	$ima = trim($word);
	$ima = substr($ima, 4);				 //saakam ar naakosho charu aiz [img
	$ima = str_replace("]", "", $ima);	  //beigaas novaacam ]
	if ($ima==$nrpk){					   //jaasanaak ciparam, kuram jaabuut vienaadam
	  $word='<br/><a href="images/article/'.$aid.'_'.$ima.'.'.$type.'" rel="thumbnail"><img src="images/article/'.$aid.'_'.$ima.'_s.'.$type.'" class="center"/></a><br/>';
	}
	else $word=$ima;
  }
  $newarray[] = $word;
  $str = implode(" ",$newarray);
}
print_r($array);
print_r($newarray);
//aaa [img1] ccc [img2] ddd [img3] eee
return $str;
 }

Edited by element
Link to comment
Share on other sites

×
×
  • Create New...