<?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[PHP - problema sostituzione stringe con funzione preg_replace]]></title><description><![CDATA[<p dir="auto">Ciao a tutti,</p>
<p dir="auto">ho un problema con una pagina php che non riesco proprio a risolvere.<br />
vorrei leggere un file di testo da php e modificare una riga con un altra utilizzando la funzione preg_replace.</p>
<p dir="auto">il file di testo contiene un elenco di righe come questa:<br />
host=192.168.1.13 nameServ=cpuLoad alert=no</p>
<p dir="auto">poi la pagina php dovrebbe leggere questa riga e sostituirla con:<br />
host=192.168.1.13 nameServ=cpuLoad alert=yes</p>
<p dir="auto">ecco il codice:</p>
<p dir="auto">// questa è la stringa che vado a ricercare<br />
60 if (preg_match ("/(host=$ipaddress nameServ=$service) alert=\w+/i", $content, $match)){</p>
<p dir="auto">//qui salvo la parte tra parentesi in $pattern<br />
61 $pattern = $match[0];</p>
<p dir="auto">//assegno a $replacement la stringa che volgio sostituire<br />
62 $replacement = $match[1].' alert=yes';</p>
<p dir="auto">//effettuo la sostituzione<br />
//$content contiene il file di testo che vado a leggere<br />
63 preg_replace($pattern, $replacement, $content);<br />
64}</p>
<p dir="auto">l'errore che restituisce la pagina è:</p>
<p dir="auto">Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in C:\web\openeyes\alert.php on line 63</p>
<p dir="auto">help me please!!</p>
]]></description><link>https://dev.connect.gt/topic/29554/php-problema-sostituzione-stringe-con-funzione-preg_replace</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Dec 2026 01:23:29 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/29554.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Mar 2007 15:41:39 GMT</pubDate><ttl>60</ttl></channel></rss>