I am trying to match a certain string – then return, lets say 3 characters before and after that string. How would I do that? Here is my current code:
<?php
$data = file_get_contents('all.htm');
$regex = '/span/';
preg_match($regex,$data,$match);?>
<pre>
<?php var_dump($match);?>
</pre>
And that returns:
array(1) {
[0]=>
string(4) "span"
}
This will match up to 3 characters before and after a specified string (here is “span”)
You can pick up the adjacent characters from the match array.