salve,
utilizzando questo codice (che fa parte di una funzione a cui va passato l'argomento $string):
codice:
/* get [ all object ...] */
preg_match_all("/(\[OBJECT[^\]]+\])(.*)(\[\/OBJECT_SPAN\])/", $string, $occurrence);
$NewString = $string;
reset($occurrence);
while(list($kO, $obj) = each($occurrence[1])) {
/* get properties from [object ...] */
preg_match_all("/([\w]+='[àèìòùé\w\s\#\%\_\.\,\/\+\-]+')/", $obj, $KK);
/* replace key='val' to key=val */
$PR = preg_replace("/([\w]+)='([àèìòùé\w\s\#\%\_\.\,\/\+\-]+)'/", "$1=$2", $KK[1]);
/* convert obtained string to associative array */
$props = array();
foreach($PR as $line) {
list($key, $val) = explode('=', $line);
$props[$key] = $val;
}
$thisObject = "";
if($props['type'] == "SPAN") {
$titleSpan = ($props['L'] != "null") ? ' title="'.url_decode($props['L']).'"' : "" ;
$pFont = explode(",", $props['F']);
//line-height per alzare il line height indipendentemente dalla dimensione del testo
$lh_default = "140%";//1.41;
$familyFont = ($pFont[0] != "default") ? "font-family:'".url_decode($pFont[0])."';" : "" ;
$sizeFont = (($pFont[1] != "0em") && ($pFont[1] != "0px")) ? 'font-size:'.$pFont[1].';line-height:'.$lh_default.';' : "" ;
$weightFont = ($pFont[2] != "none") ? 'font-weight:'.$pFont[2].';' : "" ;
$styleFont = ($pFont[3] != "none") ? 'font-style:'.$pFont[3].';' : "" ;
$colorFont = ($pFont[4] != $pFont[9]) ? 'color:#'.$pFont[4].';' : "" ;
$colorBkgFont = ($pFont[5] != $pFont[10]) ? 'background:#'.$pFont[5].';' : "" ;
$alignText = ($pFont[6] != "none") ? 'text-align:'.$pFont[6].';' : "" ;
$decoreText = ($pFont[7] != "none") ? 'text-decoration:'.url_decode($pFont[7]).';' : "" ;
$transformText = ($pFont[8] != "none") ? 'text-transform:'.$pFont[8].';' : "" ;
$FormatSpan = $familyFont.$sizeFont.$weightFont.$styleFont.$colorFont.$colorBkgFont.$alignText.$decoreText.$transformText;
$FormatSpan = ($FormatSpan != "") ? ' style="'.$FormatSpan.'"' : "" ;
$thisObject = '<span'.$FormatSpan.''.$titleSpan.'>'.$FormattedText.'</span>';
}
$NewString = str_replace($obj, $thisObject, $NewString);
}
e alla funzione che utilizza il precedente codice gli passo un testo simile:
Aliquam sed turpis metus, vel ultricies leo. Morbi nec elit neque.
<hr />
[OBJECT type='SPAN' F='Courier+New,0em,bold,none,252525,ffffff,none,no ne,none,252525,ffffff' L='null']tanto va la gatta al largo che ci lascia lo zampino[/OBJECT_SPAN]
<hr />
Ut ac scelerisque turpis. Etiam dapibus dolor sed justo placerat id mollis nisi placerat
dove la stringa "tanto va la gatta al largo che ci lascia lo zampino" deve essere formattata con i parametri indicati in F
la conversione avviene perfettamente solo che c'è qualche pezzo in più e adesso mostro il codice html che viene creato:
codice:
<span style="font-family:'Courier New';font-weight:bold;">
tanto va la gatta al largo che ci lascia lo zampino</span>
tanto va la gatta al largo che ci lascia lo zampino[/OBJECT_SPAN]
insomma il testo in rosso è in più!!! come modifico il codice per fare in modo che il testo in più sparisca??
Grazie in anticipo..