Klez Posted January 16, 2005 Report Posted January 16, 2005 preg_replace("/\[file\]((\s|.)+?)\[\/file\]/", file2Link(\\1, $tFaili, '?id=faili'), $teksts); jautaajums taads: f-cija file2Link(\\1, $tFaili, '?id=faili') izpildaas ar vieninieku ir teksts, kur pa vidu ir shaads: te smuks fails: [file]2[/file] taatad ar preg_replace shii vietaa [file]2[/file] tiek izsaukta funkcija file2Link(\\1, $tFaili, '?id=faili') f-cijai file2Link ir 3 parametri $failaID, $tFaili, '?id=faili' kaa lai panaak, ka preg_replace nodod f-cijai pirmo parametru (failaID) to kas ir starp [file]2[/file] ja palaizh shitaa: preg_replace("/\[file\]((\s|.)+?)\[\/file\]/", file2Link(\\1, $tFaili, '?id=faili'), $teksts); tad $fileID vienmeer ir cipars 1 ja shaadi: preg_replace("/\[file\]((\s|.)+?)\[\/file\]/", file2Link("\\1", $tFaili, '?id=faili'), $teksts); tad arii vienmeer $fileID = 1 helpppp
bubu Posted January 16, 2005 Report Posted January 16, 2005 Nezinu, ko tā file2link fja tev dara, bet ja tev vajag dabūt to skaitli, kas ir iekš [file] un [/file] tagiem formā ?id=xxx, tad var darīt šādi: preg_replace("/\[file\](.*)\[\/file\]/", "?id=\\1", $teksts); bet ja vajag padot tai funkcijai kā pirmo parametru, to kas iekš tagiem, tad: if (preg_match("/\[file\](.*)\[\/file\]/", $teksts, $tmp)) { echo file2link($tmp[1], ??, ??); // nezinu, ko tev vajag kā otro un trešo parametru padot }
Klez Posted January 21, 2005 Author Report Posted January 21, 2005 shis arii nestraadaa kauta kaa: taatad: <? $text = "te smuks texts. te ir viens fails [file]1[/file] un te ir smuka bildiite[file]2[/file]"; function file2Link($id, $table, $fileUrl){ //fcija panjem no DB ieraxu ar ID kas vinjai ir padots ($id) $all = mysql_query("SELECT name FROM $table WHERE id = $id") or print("f2l: ".mysql_error()); if (mysql_num_rows($all) > 0){ $one = mysql_fetch_array($all); $f = '<a href="'.$fileUrl.'?f='.$id.'">'.$one['name'].'</a>'; @mysql_free_result($all); return $f; }else{ return "Fails kaut kur noklīdis"; } } echo preg_replace("/\[file\]((\s|.)+?)\[\/file\]/", file2Link(\\1, $tFaili, '?id=faili'), $text); ?> kaa ieksh preg_replace var palaist fciju? shajaa gadiijumaa taa funkcija neizpildaas, fai arii $id vienmeer = 1 tachu ja teksts satur vairaakus [file][/file], tad izvadaas tikai pirmais
рпр Posted January 24, 2005 Report Posted January 24, 2005 taa nedriikst izmantot preg_replace kaa tu to dari, ja tu gribi , lai vareetu ar preg replace atrastos stringus izmantot funkcijaas, tad tev jaaizmanto cita funkcija - preg_replace_callback.
Roze Posted January 24, 2005 Report Posted January 24, 2005 kaa ieksh preg_replace var palaist fciju? Ar preg_replace_callback() funkcijai attieciigi tieks padotas 'nomatchotās' vērtības un tu vari darīt tālāk ko gribi. Teiksim manā variantā noderēja šādi: $content = preg_replace_callback("/<text>(.*)<\/text>/Uis",create_function('$matches','return str_replace("\n","\\\\n",$matches[0]);'),$content);
Analgiins Posted January 31, 2005 Report Posted January 31, 2005 lai ieksh preg_replace vareetu palaist funkciju, jaaizmanto e modifier, piemeers no manuaalja: <?php preg_replace("/(<\/?)(\w+)([^>]*>)/e", "'\\1'.strtoupper('\\2').'\\3'", $html_body); ?>
Recommended Posts