Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di lnessuno
    Registrato dal
    Feb 2002
    Messaggi
    2,732

    [Espressioni regolari] Dividere il testo in array, in base alle immagini...

    Mi capita poco di dover lavorare con espressioni regolari, e quando mi capita è sempre un bagno di sangue

    Quello che dovrei fare è partire da un testo, tipo

    <h1>Prima pagina!</h1><div id='text'>Button enhances standard form elements like button, input of
    type submit or reset or anchors to themable buttons with appropiate
    mouseover and active styles...
    E suddividerlo in qualcosa di simile a questo:
    codice:
    array(
        [0] => "<h1>Prima pagina!</h1><div id='text'>"
        [1] => array(
               [url] => http:\\localhost/test/app/webroot/files/image/immagine.png
               [width] => 250
               [height] => 187
               [style] => float:right;margin-left:10px
               [alt] => testo alternativo
        )
        [2] => "Button enhances standard form elements like button, input of 
    type submit or reset or anchors to themable buttons with appropiate 
    mouseover and active styles..."
    ... insomma vorrei suddividere il testo in modo tale da poter avere i dati delle immagini in arrays, nelle loro posizioni originali, gestibili in modo semplice per poterne manipolare i parametri...

    Qualche aiuto? Per ora riesco ad avere un elenco delle sole immagini, ma sono ben lontano dal riuscire ad ottenere qualcosa di simile a ciò che mi serve...

  2. #2
    Utente di HTML.it L'avatar di lnessuno
    Registrato dal
    Feb 2002
    Messaggi
    2,732
    per ora, con qualche altro tentativo sono riuscito ad arrivare a questo:

    codice:
    preg_match_all('/<img[^>]+>/i',$node['text']['value'], $result); 
    
    foreach( $result as $tmp) {
    	foreach($tmp as $id => $img_tag) {
    		preg_match_all('/(alt|title|width|height|style|src)=("[^"]*")/i',$img_tag, $img[$id]);
    	}
    }
    
    debug($img);
    Che mi restituisce
    codice:
    Array
    (
        [0] => Array
            (
                [0] => Array
                    (
                        [0] => style="float:right;margin-left:10px"
                        [1] => src="http:\\localhost/test/app/webroot/files/image/Sfondo.png"
                        [2] => height="187"
                        [3] => width="250"
                    )
    
                [1] => Array
                    (
                        [0] => style
                        [1] => src
                        [2] => height
                        [3] => width
                    )
    
                [2] => Array
                    (
                        [0] => "float:right;margin-left:10px"
                        [1] => "http:\\localhost/test/app/webroot/files/image/Sfondo.png"
                        [2] => "187"
                        [3] => "250"
                    )
    
            )
    
        [1] => Array
            (
                [0] => Array
                    (
                        [0] => src="http:\\localhost/test/app/webroot/files/image/32.jpg"
                        [1] => alt="immagine"
                        [2] => height="50px"
                        [3] => width="40px"
                    )
    
                [1] => Array
                    (
                        [0] => src
                        [1] => alt
                        [2] => height
                        [3] => width
                    )
    
                [2] => Array
                    (
                        [0] => "http:\\localhost/test/app/webroot/files/image/32.jpg"
                        [1] => "immagine"
                        [2] => "50px"
                        [3] => "40px"
                    )
    
            )
    
    )
    Già non è male, come risultato, ma come faccio a mantenere il tutto nelle posizioni originali?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.