<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Preg_match e controllo stringa]]></title><description><![CDATA[<p dir="auto">Buon giorno sto cercando attraverso questa funzione di trovare  all'interno di un testo due parole, link e allegato.<br />
ho provato in questo modo ma è troppo macchinoso e vorrei sapere  cortesemente come posso ottimizzare per trovare tutte le soluzioni.<br />
codice PHP:<br />
//FARE CONTROLLO  SU LINK SE GIà ESISTENTE NON AGGIORNARE--&gt;TROVARE LINK ALL'INTERNO  DEL TESTO<br />
if (!preg_match("/p=$healthy[0]/i", $txtTesto)) {<br />
//se non esiste creo link alla  pagina<br />
$newphrase = str_replace($healthy, $yummy, stripslashes($txtTesto));<br />
//echo "Se link non esiste lo  creo";exit;<br />
}<br />
elseif(!preg_match("/allegato/i", trim($txtTesto))) {<br />
//echo "'$newphrase' contains a  'allegato' or 'Allegato'!";<br />
$newphrase=str_replace("allegato","&lt;a href='".$base_dir.$selArgomento."/News/".inv_data(trim($txtDataIns))."/".$phFileAllegato."'  onclick="window.open(this.href);return false;"  title="$txtAllegato"&gt;allegato&lt;/a&gt;",$newphrase);<br />
//echo "Testo New: "  .htmlentities($newphrase);exit;<br />
}<br />
elseif(!preg_match("/p=$healthy[0]/i", $txtTesto) &amp;&amp; !preg_match("/allegato/i", trim($txtTesto))) {<br />
//echo "'$newphrase' contains sia  link che allegato!";<br />
$newphrase=str_replace("allegato","&lt;a href='".$base_dir.$selArgomento."/News/".inv_data(trim($txtDataIns))."/".$phFileAllegato."'  onclick="window.open(this.href);return false;"  title="$txtAllegato"&gt;allegato&lt;/a&gt;",$newphrase);<br />
//echo "Testo New: "  .htmlentities($newphrase);exit;<br />
}</p>
<p dir="auto">Praticamente, devo controllare se nel testo:</p>
<ol>
<li>è presente solo la parola link</li>
<li>solo la parola allegato</li>
<li>oppure tutte e due.</li>
</ol>
<p dir="auto">e farmi restituire il risultato dalla stessa variabile $newphrase, che  poi mi serve per fare un Update.</p>
<p dir="auto">Potreste dirmi cortesemente come fare?<br />
Io intanto continuo a scervellarmi.</p>
<p dir="auto">Grazie mille e buona giornata.</p>
]]></description><link>https://dev.connect.gt/topic/126253/preg_match-e-controllo-stringa</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 18:40:31 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/126253.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Apr 2010 06:57:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Preg_match e controllo stringa on Mon, 26 Apr 2010 09:58:25 GMT]]></title><description><![CDATA[<p dir="auto">ho risolto utilizzando la funzione str_pos per le due opzioni cosi:</p>
<pre><code class="language-php">$findme = 'href=\"'.$healthy[0].'\"';
$pos = strpos($txtTesto, $findme);
if ($pos !== false) {   
    $txtTesto = str_replace($healthy, $yummy, stripslashes($txtTesto));
}

$findme = "allegato";
$pos = strpos($txtTesto, $findme);
if ($pos !== false) {
    if($phFileAllegato!="" || $txtPhAllegato!=""){
        $txtTesto=str_replace("allegato","&lt;a href='".$base_dir.$selArgomento."/News/".inv_data(trim($txtDataIns))."/".$phFileAllegato."' onclick=\"window.open(this.href);return false;\" title=\"$txtAllegato\"&gt;allegato&lt;/a&gt;",$txtTesto);
    }
}
echo htmlentities($txtTesto);exit;
</code></pre>
<p dir="auto">Cosi facendo sembra prendere tutte le soluzioni.<br />
grazie comunque a tutti... <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--smile" style="height:1.4em;width:auto;vertical-align:middle" title=":D" alt="😄" /></p>
]]></description><link>https://dev.connect.gt/post/906955</link><guid isPermaLink="true">https://dev.connect.gt/post/906955</guid><dc:creator><![CDATA[antagonia]]></dc:creator><pubDate>Mon, 26 Apr 2010 09:58:25 GMT</pubDate></item></channel></rss>