regex - PHP: Preg_Match, trying to return a certain number of characters ahead of match -


i trying match string - return, lets 3 characters before , after string. how that? here current code:

<?php $data = file_get_contents('all.htm'); $regex = '/span/'; preg_match($regex,$data,$match);?> <pre> <?php var_dump($match);?> </pre> 

and returns:

array(1) {   [0]=>   string(4) "span" } 

this match 3 characters before , after specified string (here "span")

/(.{0,3})span(.{0,3})/ 

you can pick adjacent characters match array.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -