ffgghh Posted April 12, 2006 Report Share Posted April 12, 2006 LIeta ir sekojosha: notiek selekts no datubaazes kaarezultaataa ieguustam mainiigo $text ar tekstu kuraa iekshaa ir atrodami dazhaadi {bla1} {blabla1} {1bla1} {11b1la1} utt... [visi {} ielikti smukās iekiavās] Kā vis ātrāk un vienkāršāk katru no tiem aizvietot ar teiksim select name from tabula where id={1bla1} ??? Link to comment Share on other sites More sharing options...
Delfins Posted April 12, 2006 Report Share Posted April 12, 2006 ja pareizi sapratu $ids = preg_replace( '/}\s{/', ',', $text ); $ids = preg_replace( '/}|{/', '', $ids ); ... select .. where ID in ($ids) Link to comment Share on other sites More sharing options...
ffgghh Posted April 12, 2006 Author Report Share Posted April 12, 2006 Piemēram: $text="Tu vēlies ievietot {bla1} pagarāku PHP kodu, tad izmanto paste.php.lv sniegtās iespējas un ierakstā atstāj atsauci uz to! Pirms rakstīt, {bubu} izlasi bubu sarūpēto {asdxs} satura rādītāju. Kā arī, izmanto meklēšanas iespēju. Labāk ir patērēt vairāk laika {asdf}meklējot un atrodot (neatrodot:), nekā pēc tam tapt nolamātam." tabula id name 1 bla1 2 bubu 3 asdxs 4 asdf Vot kā to izdarīt? Link to comment Share on other sites More sharing options...
ffgghh Posted April 12, 2006 Author Report Share Posted April 12, 2006 (edited) Šķiet ka šo problēmu atrisināju: print preg_replace_callback("/\\{(.*?)\\}/",create_function('$m','return "cic ".$m[0]." text ";'),$text); taču radīju jaunu: Kā create_function ietvaros izpildīt get_reply no MySQL ??? Kas tur bija jānorāda lai viņš to citu f-kciju izsauktu - citādi man errorus met un baltu lapu rāda? Edited April 12, 2006 by ffgghh Link to comment Share on other sites More sharing options...
Delfins Posted April 12, 2006 Report Share Posted April 12, 2006 (edited) 1.) dabū visus {id} - uztaisi hashtable 2.) izselektē no DB visus {id} no 1. hashtabulas un ieliec citā hashtabulā 3.) preg_replace padod f-ju, kas atgriež vērtību no jaunas hashtabulas Edited April 12, 2006 by Delfins Link to comment Share on other sites More sharing options...
ffgghh Posted April 12, 2006 Author Report Share Posted April 12, 2006 (edited) HA - ir pavisam vienkārši preg_replace_callback("/\\{(.*?)\\}/", "Script", $text)) un function Script($match) { return get_reply("SELECT kuku FROM tabula WHERE name='".$match[1]."' ;"); } PALDIES par helpu!!! Problem Solved! Edited April 12, 2006 by ffgghh Link to comment Share on other sites More sharing options...
v3rb0 Posted April 12, 2006 Report Share Posted April 12, 2006 ..un ja patrāpīsies 100x {asd} tad 100x selectu izpildīsi? :) Link to comment Share on other sites More sharing options...
ffgghh Posted April 27, 2006 Author Report Share Posted April 27, 2006 aha - tāc jau ir mērķis... Link to comment Share on other sites More sharing options...
GedroX Posted April 27, 2006 Report Share Posted April 27, 2006 Izmanto MySQL funkcijas. Būs vienā select-ā. Link to comment Share on other sites More sharing options...
ffgghh Posted April 27, 2006 Author Report Share Posted April 27, 2006 Iemet piemēru? Link to comment Share on other sites More sharing options...
GedroX Posted April 27, 2006 Report Share Posted April 27, 2006 Esmu rakstījis funkcijas tikai postgresql-ā. Paņem jaunāko MySQL, tā manuāli - un uz priekšu. Link to comment Share on other sites More sharing options...
nemec Posted April 27, 2006 Report Share Posted April 27, 2006 (edited) $text = selectee ar baazi; $varablis_aizvietoshanai['id'] = name; preg_match_all("#\[mat\](.*?)\[/mat\]#si",$text,$tex_mas); for ($i=0; $i < count($tex_mas[0]); $i++) { $formula = trim($tex_mas[1][$i]); $formula_ke = $tex_mas[0][$i]; $pos = strpos($text, $formula_ke); if (isste($varablis_aizvietoshanai[$formula])) { $text = substr_replace($text, $varablis_aizvietoshanai[$formula],$pos,strlen($formula_ke)); } } echo $text; uz aatro Edited April 27, 2006 by nemec Link to comment Share on other sites More sharing options...
ffgghh Posted April 28, 2006 Author Report Share Posted April 28, 2006 (edited) HMM - a man liekas ka man sanaaca vienkaarshaak... function SmileyScript($match) { $filename=get_reply("SELECT file FROM smiley WHERE name='".$match[1]."' ;"); if(!$filename){return "{".$match[1]."}";}else{return "<img src=\"smiley1/".$filename.".gif\">";} } function ShowSmileyScript($text) { return nl2br(preg_replace_callback("/\\{(.*?)\\}/", "SmileyScript", $text)); } $rez=query("SELECT text FROM message;"); while($row=fetch($rez)){echo "<p>".ShowSmileyScript($row['text'])."</p>";} Vot ja selecteejot $text prieksh ShowSmileyScript($text) vareetu no MySQL jau izvilkt ar aizvietotiem {} elementiem - tad buutu kruta. Edited April 28, 2006 by ffgghh Link to comment Share on other sites More sharing options...
Recommended Posts