Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I do string replace for xml nodes using simpleXML?
    primarykey
    data
    text
    <p>I was wondering if you could help. The code below pulls in XML data from an external XML file and then re-formats it into table data. All works perfect. However, some of the data from the XML file needs to be changed and so is it possible to use str_replace or preg_replace for each individual node below? I do not know how to write the str_replace for each node. I thought perhaps something like this "<strong>{$hour->weatherCod} . str_replace (10, Sun);</strong>" would work but it doesn't. Would smeone be able to tell me the correct format? I need something easy as I am more of an actionscript guy rather than php.</p> <p>Many thanks if youre able to help!</p> <pre><code>&lt;?php // load SimpleXML $data = new SimpleXMLElement('xml_file.xml', null, true); foreach($data-&gt;weather as $weather) { foreach ($weather-&gt;hourly as $hour) { echo &lt;&lt;&lt;EOF &lt;tr&gt; &lt;td&gt;{$weather-&gt;day}&lt;/td&gt; &lt;td&gt;{$weather-&gt;Ctemp1}&amp;deg;c&lt;/td&gt; &lt;td&gt;{$weather-&gt;Ctemp2}&amp;deg;c&lt;/td&gt; &lt;td&gt;{$hour-&gt;time}&lt;/td&gt; &lt;td&gt;{$hour-&gt;tempC}&amp;deg;c&lt;/td&gt; &lt;td&gt;{$hour-&gt;tempF}&amp;deg;f&lt;/td&gt; &lt;td&gt;{$hour-&gt;windMiles}mph&lt;/td&gt; &lt;td&gt;{$hour-&gt;windKmph}km/h&lt;/td&gt; &lt;td&gt;{$hour-&gt;windDegree}&amp;deg;&lt;/td&gt; &lt;td&gt;{$hour-&gt;winddir}&lt;/td&gt; &lt;td&gt;{$hour-&gt;weatherCod}&lt;/td&gt; &lt;td&gt;{$hour-&gt;weatherIconUrl}&lt;/td&gt; &lt;td&gt;{$hour-&gt;precipMM}mm&lt;/td&gt; &lt;td&gt;{$hour-&gt;humidity}%&lt;/td&gt; &lt;td&gt;{$hour-&gt;visibility}&lt;/td&gt; &lt;td&gt;{$hour-&gt;pressure}mb&lt;/td&gt; &lt;td&gt;{$hour-&gt;cloudcover}&lt;/td&gt; &lt;td&gt;{$hour-&gt;sigHeight_m}m&lt;/td&gt; &lt;td&gt;{$hour-&gt;swellHeight_m}m&lt;/td&gt; &lt;td&gt;{$hour-&gt;swellDir}&amp;deg;&lt;/td&gt; &lt;td&gt;{$hour-&gt;swellPeriod_secs}s&lt;/td&gt; &lt;td&gt;{$hour-&gt;waterTemp_C}&amp;deg;c&lt;/td&gt; &lt;td&gt;{$hour-&gt;waterTemp_F}&amp;deg;f&lt;/td&gt; &lt;/tr&gt; EOF; } } echo '&lt;/table&gt;'; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload