Jump to content
php.lv forumi

Nolaadeetie Strringi....


andre

Recommended Posts

karoche, ir taads teksts :

"asdasdas <!#MODULE:asd#>asdf asdf asdf <!#MODULE:fds#> asd asd as <!#MODULE:iuy#> sada"

 

uztaisiit funkciju vai skriptu, kas beigaas izdariis luuk taaaa (tipa lai rezultaats buutu taads):

 

"asdasdas ".$asd."asdf asdf asdf ".$fds." asd asd as ".$iuy." sada"

Link to comment
Share on other sites

Nu vienkaarshakajaa un brutaakalajaa variantaa..

 

$string = "asdasdas <!#MODULE:asd#>asdf asdf asdf <!#MODULE:fds#> asd asd as <!#MODULE:iuy#> sada";

$string = str_replace('<!#MODULE:','".$',$string);

$string = str_replace('#>','."',$string);

Link to comment
Share on other sites

ja vaig ieguut tieshi

"asdasdas ".$asd."asdf asdf asdf ".$fds." asd asd as ".$iuy." sada"

izmanto Roze doto piemeeru, vai arii, ja gribas buut advanceetam ;) tad

<?

$patt = '/<!#MODULE:(.*)#>/iU';

$repl = '".$$1."';

$string = preg_replace($patt, $repl, $string);

?>

 

ja vaig jau ar saliktiem visiem mainiigajiem, tad

<?

$patt = '/<!#MODULE:(.*)#>/iUe';

$repl = '$$1';

$string = preg_replace($patt, $repl, $string);

?>

Link to comment
Share on other sites

ideja ir taada, ka jaatorod stringaaa <#MODULE:asd#>

jaanoslasa,kas ir peec MODULE: (<#MODULE:?#>) un pirms "#>"

dotajaa variantaa ?=asd

 

 

un tad jaaieliek mainiigais $$temp. kur $temp="asd" (tas kas sekoja peec "MODULE:")

Link to comment
Share on other sites

×
×
  • Create New...