Page 2 of 2
Posted: Sat Aug 24, 2002 5:06 pm
by volka
Code: Select all
<html><body>
<?php
$search = array('!foo!', '!allice!');
$replace = array('bar', 'bob');
$subject = array('foo allice foo', 'foo allice foo');
print_r(preg_replace($search, $replace, $subject, 1));
?>
</body></html>
-->
Array ( [0] => bar bob foo [1] => bar bob foo )
you see: it limits the use of
each search entry in
each source line

Posted: Sat Aug 24, 2002 5:10 pm
by Silver_Eclipse
yea but my subject is an array already. it was a file that was read into an array.
Posted: Sat Aug 24, 2002 5:13 pm
by volka
do you need that array or was it just the comfort of file() ?

if there's no (other) need for that array try fopen() and fread()
Posted: Sat Aug 24, 2002 5:20 pm
by Silver_Eclipse
i used file() because i couldnt get fread to print right and i used the array created by file() to print out only certain lines of the file using for and each.
Posted: Sat Aug 24, 2002 5:41 pm
by volka
hmm...no good advices left
maybe you should read the file with fread, do the replace and explode it to an array.
maybe some other hints:
-
preg_replace_callback
- if you're replacing constants strings (using PCRE only because of the limit-option) you can do this by strpos, substr and .
- others know a good trick
