Pentiums Posted February 7, 2008 Report Share Posted February 7, 2008 <?php $bla = include("tops.html"); $ble = str_replace('vecais_teksts','jaunais_teksts', $bla); echo $ble; ?> iekšā failā tops.html atrodas teksts "vecais_teksts" un viņu vajag repleisot uz tekstu "jaunais_teksts"! Kas man te nav pareizi? Link to comment Share on other sites More sharing options...
andrisp Posted February 7, 2008 Report Share Posted February 7, 2008 include neatgriež faila saturu, bet iekļauj failu, izpildot tā kodu (ja tur ir kods, protams). izmanto file_get_contents vai ko tādu. Link to comment Share on other sites More sharing options...
Pentiums Posted February 8, 2008 Author Report Share Posted February 8, 2008 (edited) <?php $ble = 'kreisais vidus labais'; echo str_replace('kreisais(.*?)labais', 'Jaunais teksts', $ble); ?> Kur ir kļūda? es iegūstu atkal to pašu "kreisais vidus labais" ja man vajag aizvietot to visu kas atrodas starp "kreisais" un "labais" Edited February 8, 2008 by Pentiums Link to comment Share on other sites More sharing options...
andrisp Posted February 8, 2008 Report Share Posted February 8, 2008 pirmkārt, str_replace neatbalsta regulārās expresijas. Izmanto preg_replace. Link to comment Share on other sites More sharing options...
Pentiums Posted February 8, 2008 Author Report Share Posted February 8, 2008 ar preg_replace dabūju šādu warningu Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\sms.php on line 4 Link to comment Share on other sites More sharing options...
andrisp Posted February 8, 2008 Report Share Posted February 8, 2008 (edited) Nu nepareizs regexps. Bet vispār tas nozīmē, ka trūkst sākuma un beigu atdalītājs. Es parasti izmantoju /. Tipa '/kreisais(.*?)labais/' Edited February 8, 2008 by andrisp Link to comment Share on other sites More sharing options...
Recommended Posts