auto link word link in content

If I understand correctly … first of all you need to match everything inside paragraphs using regex.

$content = "<p>some text which includes test1 and test2 etc</p>";
preg_match_all("/<\s*p[^>]*>([^<]*)<\s*\/\s*p\s*>/", $content);

then you can use your code.