Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Preg_match e controllo stringa

    Buon giorno sto cercando attraverso questa funzione di trovare all'interno di un testo due parole, link e allegato.
    ho provato in questo modo ma è troppo macchinoso e vorrei sapere cortesemente come posso ottimizzare per trovare tutte le soluzioni.
    Codice PHP:
    //FARE CONTROLLO SU LINK SE GIà ESISTENTE NON AGGIORNARE-->TROVARE LINK ALL'INTERNO DEL TESTO
    if (!preg_match("/p=$healthy[0]/i"$txtTesto)) {
        
    //se non esiste creo link alla pagina
        
    $newphrase str_replace($healthy$yummystripslashes($txtTesto));
        
    //echo "Se link non esiste lo creo";exit;
    }
    elseif(!
    preg_match("/allegato/i"trim($txtTesto))) {
        
    //echo "'$newphrase' contains a 'allegato' or 'Allegato'!";
        
    $newphrase=str_replace("allegato","[url='".$base_dir.$selArgomento."/News/".inv_data(trim($txtDataIns))."/".$phFileAllegato."']allegato[/url]",$newphrase);
        
    //echo "Testo New: " .htmlentities($newphrase);exit;
    }
    elseif(!
    preg_match("/p=$healthy[0]/i"$txtTesto) && !preg_match("/allegato/i"trim($txtTesto))) {
        
    //echo "'$newphrase' contains sia link che allegato!";
        
    $newphrase=str_replace("allegato","[url='".$base_dir.$selArgomento."/News/".inv_data(trim($txtDataIns))."/".$phFileAllegato."']allegato[/url]",$newphrase);
        
    //echo "Testo New: " .htmlentities($newphrase);exit;

    Praticamente, devo controllare se nel testo:
    1) è presente solo la parola link
    2) solo la parola allegato
    3) oppure tutte e due.

    e farmi restituire il risultato dalla stessa variabile $newphrase, che poi mi serve per fare un Update.

    Potreste dirmi cortesemente come fare?
    Io intanto continuo a scervellarmi.

    Grazie mille e buona giornata.

  2. #2
    ragazzi buon giorno, potreste aiutarmi per favore?
    Grazie mille.

  3. #3
    ho risolto utilizzando la funzione str_pos per le due opzioni cosi:
    Codice PHP:
    $findme 'href=\"'.$healthy[0].'\"';
    $pos strpos($txtTesto$findme);
    if (
    $pos !== false) {   
        
    $txtTesto str_replace($healthy$yummystripslashes($txtTesto));
    }

    $findme "allegato";
    $pos strpos($txtTesto$findme);
    if (
    $pos !== false) {
        if(
    $phFileAllegato!="" || $txtPhAllegato!=""){
            
    $txtTesto=str_replace("allegato","[url='".$base_dir.$selArgomento."/News/".inv_data(trim($txtDataIns))."/".$phFileAllegato."']allegato[/url]",$txtTesto);
        }
    }
    echo 
    htmlentities($txtTesto);exit; 
    Cosi facendo sembra prendere tutte le soluzioni.
    grazie comunque a tutti...

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 © 2024 vBulletin Solutions, Inc. All rights reserved.