Venom Posted February 19, 2003 Report Share Posted February 19, 2003 Ierosinājums noņemts. Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 Ak jā, un vēl varētu izķert funkcijas, lai ieliktos links uz php.net manuāļiem (esmu redzējis tādas fičas phpclubneta forumā). It goes something like this. $match='/([a-z_]+)(/Uim'; $s=$mysql_text; while(preg_match($match,$s,$c)) { $str=$c[1]; $str=str_replace('_','-',$str); $s=str_replace($c[1],'<a target=_blank href="http://www.php.net/function.'.strtolower($str).'.php">'.$c[1].'</a>',$s); } Link to comment Share on other sites More sharing options...
laacz Posted February 19, 2003 Report Share Posted February 19, 2003 a) bija doma ievietot supportu tagam vai vismaz php syntax_highlight pievienot tagam, bet neizdevās, jo attiecīgās php funkcijas visu outputo directly, savukārt, man ar ob_start, ob_get_contents, etc neizdevās jamo piemocīt, lai darās, kā vajag. b) var paprovēt, bet tas būs tikai jaunajiem postiem (kad paprovēšu:), jo jamais saturu parsē pirms inserta datubāzē (kas man nav saprotams); Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 Mļāviens, es ar to highlightu arī biju nomocījies. Stringi iekš datubāzes tiek dzīti ar htmlspecialchars($str,ENT_QUOTES); Uz parādīšanu sākas dancis: //setting up colors for code highlighting $COLORS=array( 'highlight.comment'=>'#0077ff', 'highlight.default'=>'#dd4444', 'highlight.keyword'=>'#4444cc', 'highlight.string'=>'#00aa55' ); while(list($key,$val)=each($COLORS)) { ini_set($key,$val); } //highlighting code while(preg_match('/ ((.|n)+) /Umi',$s,$c)) //izķeram code tagu { if (isset($c[1])) { $str=$c[1]; if (preg_match('/([code|code])/',$str)) { $s=str_replace($str,$ALERT.'<font color=red>DOUBLING</font>'.$str,$s); //te es vienkārši aizliedzu iekš code ievietot citu code break; } //tā kā iekš datu bāzes visādi &, < etc tiek ievietoti kā &<, //bet highlightam vajag normālu kodu, es to visu apgriežu: //samainu < uz < utt: $trans = get_html_translation_table(HTML_ENTITIES); $trans = array_flip($trans); $str = strtr($str, $trans); $str=trim($str); if (strlen($str)>$CHARS['code']) //te ir aizliegums postēt pārāk garus koda gabalus { // $s=str_replace($str,'<br><font color=red>['.$CHARS['code'].' char limit for highlighting exceed]</font>|<br>'.$str,$s); break; } $str=str_replace("n","",$str); $str=str_replace('<?','#php_start#',$str); $str=str_replace('?>','#php_end#',$str); //highlight_string nestrādā ja kods nav iekš <? ?>; tāpēc no sākuma to pievienojam $str=highlight_string('<?'.$str.'?>',1); //jupee! highlight_string ir otrs parametrs, kas, if set to TRUE, neecho oputputu uzreiz. $pos=strpos($str,'<?'); $str=substr($str,0,$pos).substr($str,$pos+5); $pos=strrpos($str,'?>'); $str=substr($str,0,$pos).substr($str,$pos+5); //un pēc tam noņemam, saglabājot vairākus <? un ?> iekš viena code gabala $str=str_replace('#php_start#','<?',$str); $str=str_replace('#php_end#','?>',$str); $s=str_replace($c[0],$str,$s); //un nomainām koda gabalu sākotnējā stringā } } Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 Un vēl ko es postos izdarīju: str_replace("t",' &nsbp; &nsbp; &nsbp;',$post); Link to comment Share on other sites More sharing options...
laacz Posted February 19, 2003 Report Share Posted February 19, 2003 Es jau neko, bet tas tavs kods kaut ko ne tā :) Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 /me knows. highlight_string($str,1); un tanco no turienes :) Link to comment Share on other sites More sharing options...
laacz Posted February 19, 2003 Report Share Posted February 19, 2003 Tā, pārbaudam, kā nu mums CODE tags strādā ar PHP kodu tajā: <code><font color="#000000"> Šis nav PHP kods <font color="#0000CC"><? </font><font color="#FF9900">// bet šis gan ir </font><font color="#0000CC"> $txt </font><font color="#006600">= </font><font color="#0000CC">strtr</font><font color="#006600">(</font><font color="#0000CC">$txt</font><font color="#006600">, </font><font color="#0000CC">array_flip</font><font color="#006600">(</font><font color="#0000CC">get_html_translation_table</font><font color="#006600">(</font><font color="#0000CC">HTML_ENTITIES</font><font color="#006600">))); </font><font color="#0000CC"> $txt </font><font color="#006600">= </font><font color="#0000CC">preg_replace</font><font color="#006600">(</font><font color="#CC0000">"/([0-9]+);/me"</font><font color="#006600">, </font><font color="#CC0000">"chr('1')"</font><font color="#006600">, </font><font color="#0000CC">$txt</font><font color="#006600">); </font><font color="#0000CC"> $txt </font><font color="#006600">= </font><font color="#0000CC">str_replace</font><font color="#006600">(</font><font color="#CC0000">' '</font><font color="#006600">, </font><font color="#CC0000">"n"</font><font color="#006600">, </font><font color="#0000CC">$txt</font><font color="#006600">); </font><font color="#0000CC">?> </font> </font> </code> Link to comment Share on other sites More sharing options...
laacz Posted February 19, 2003 Report Share Posted February 19, 2003 Vienīgais mīnuss, pēčāk šādu postu izeditēt nav iespējams :) Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 Es gan taisīju editējamu, bet tas tā. Tur laikam kāds trim() pirms highlight_string būtu vajadzīgs, vai/un arī uz <code> CSSā jāuzliek margin:0;box:0; P.S.>man arī patīk nestandarta highlight krāsas, kas būtu vairāk piemērotas šaizilgani-violeti-pelēcīgai (серо-буро-малиновый ;)) BBS tēmai. ini_set? Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 (edited) Ē! str_replace('&#','&',$post); ! Ārzemju valodas (resp. krievu) arī jācien! P.S.>man te sāk baigi patikties :) Edited February 19, 2003 by Venom Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 (edited) Vienīgais mīnuss, pēčāk šādu postu izeditēt nav iespējams :) Idea: Tad jāhighlighto tieši prims parādīšanas, nevis dzīšanas datu bāzē :) Es atcerējos, ka man bija tā. Edited February 19, 2003 by Venom Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 2laazc: Hm, es saņēmu alertu uz mailu, bet pie Tavas atbildes apskatīsānas nevaru tikt klāt! Link to comment Share on other sites More sharing options...
laacz Posted February 19, 2003 Report Share Posted February 19, 2003 Es jamo izdzēsu. Kaut kas tomēr te nepārāk sanāk. Uz manas kastes (win32) viss smuki parsējas, highlightojas un linkojas, bet shitente -- nini :) Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 (edited) vb. palīdzēs phpinfo salīdzināšana un/vai my.cnf salīdzinājums (esp.parameter-quoting)? Edited February 19, 2003 by Venom Link to comment Share on other sites More sharing options...
Recommended Posts