Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to replace part of a file name with str_replace
    primarykey
    data
    text
    <p>I am creating a JQuery cycle for weather radar and warning images. I have the radar overlay functioning just fine. The directory containing the warning files contains 2 versions of each file but one has a similiar file names as the radar images. So I decided to use a str_replace to replace the one part of the filename from the radar images to the warning images. For some reason the str_replace is not working and I cannot for the life of me figure out why.</p> <p>Thank you in advance for any help.</p> <pre><code>// Used to get radar images echo '&lt;div class="wp-forecast-img-cur"&gt;'."\n"; $matches = array(); preg_match_all("/(a href\=\")([^\?\"]*)(\")/i", get_text('http://radar.weather.gov/ridge/RadarImg/N0R/BOX/'), $matches); foreach($matches[2] as $k =&gt; $match) { if ($k &lt; 1) continue; echo '&lt;img src="http://radar.weather.gov/ridge/RadarImg/N0R/BOX/' . $match . '" /&gt;'."\n"; } echo '&lt;/div&gt;'."\n"; // Used to get warning images echo '&lt;div class="wp-forecast-img-warn"&gt;'."\n"; $matches = array(); preg_match_all("/(a href\=\")([^\?\"]*)(\")/i", get_text('http://radar.weather.gov/ridge/RadarImg/N0R/BOX/'), $matches); foreach($matches[2] as $k =&gt; $match) { if ($k &lt; 1) continue; echo '&lt;img src="http://radar.weather.gov/ridge/Warnings/Short/BOX/' . str_replace("NOR", "Warnings", $match) . '" /&gt;'."\n"; } echo '&lt;/div&gt;'."\n"; </code></pre> <p>This line is just echoing the original file name and not replacing NOR with Warnings.</p> <pre><code>echo '&lt;img src="http://radar.weather.gov/ridge/Warnings/Short/BOX/' . str_replace("NOR", "Warnings", $match) . '" /&gt;'."\n"; </code></pre> <p>This is the get_text function in case it's needed.</p> <pre><code>function get_text($filename) { $fp_load = fopen("$filename", "rb"); if ( $fp_load ) { while ( !feof($fp_load) ) { $content .= fgets($fp_load, 8192); } fclose($fp_load); return $content; } } </code></pre> <p>Variable Dump</p> <pre><code>array(32) { [0]=&gt; string(20) "/ridge/RadarImg/N0R/" [1]=&gt; string(25) "BOX_20130703_2220_N0R.gif" [2]=&gt; string(25) "BOX_20130703_2232_N0R.gif" [3]=&gt; string(25) "BOX_20130703_2238_N0R.gif" [4]=&gt; string(25) "BOX_20130703_2243_N0R.gif" [5]=&gt; string(25) "BOX_20130703_2249_N0R.gif" [6]=&gt; string(25) "BOX_20130703_2301_N0R.gif" [7]=&gt; string(25) "BOX_20130703_2306_N0R.gif" [8]=&gt; string(25) "BOX_20130703_2318_N0R.gif" [9]=&gt; string(25) "BOX_20130703_2324_N0R.gif" [10]=&gt; string(25) "BOX_20130703_2330_N0R.gif" [11]=&gt; string(25) "BOX_20130703_2335_N0R.gif" [12]=&gt; string(25) "BOX_20130703_2347_N0R.gif" [13]=&gt; string(25) "BOX_20130703_2353_N0R.gif" [14]=&gt; string(25) "BOX_20130703_2359_N0R.gif" [15]=&gt; string(25) "BOX_20130704_0004_N0R.gif" [16]=&gt; string(25) "BOX_20130704_0016_N0R.gif" [17]=&gt; string(25) "BOX_20130704_0022_N0R.gif" [18]=&gt; string(25) "BOX_20130704_0027_N0R.gif" [19]=&gt; string(25) "BOX_20130704_0033_N0R.gif" [20]=&gt; string(25) "BOX_20130704_0045_N0R.gif" [21]=&gt; string(25) "BOX_20130704_0056_N0R.gif" [22]=&gt; string(25) "BOX_20130704_0108_N0R.gif" [23]=&gt; string(25) "BOX_20130704_0114_N0R.gif" [24]=&gt; string(25) "BOX_20130704_0125_N0R.gif" [25]=&gt; string(25) "BOX_20130704_0137_N0R.gif" [26]=&gt; string(25) "BOX_20130704_0148_N0R.gif" [27]=&gt; string(25) "BOX_20130704_0154_N0R.gif" [28]=&gt; string(25) "BOX_20130704_0206_N0R.gif" [29]=&gt; string(25) "BOX_20130704_0211_N0R.gif" [30]=&gt; string(25) "BOX_20130704_0223_N0R.gif" [31]=&gt; string(25) "BOX_20130704_0229_N0R.gif" } </code></pre>
    singulars
    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.
 

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