0

I'm trying to search for a phrase inside a .txt file using preg_match but it never gives me matches. Strange thing is if I try copying and pasting the file content in a sandbox I get good matches. This is what I tried:

$txtUrl='https://www.sec.gov/Archives/edgar/data/1411579/000110465920131796/0001104659-20-131796.txt';
$getTextS3 = file_get_contents($txtUrl, true);
$str=strip_tags($getTextS3);
 $re = '/Shares of Class A common stock/i';
  preg_match_all($re, $str, $match);
  var_dump($match);
1
  • 3
    Can you give us a sample of the text you're serching on? Commented Jan 28, 2021 at 12:08

1 Answer 1

1

You cannot find anything because there is an escaped non-breaking-space ( ) between "Shares of Class" and "A common stock". You would have to include this non-breaking space in your regex. I would advice you to write echo($str); before you execute the regex (the line with preg_match_all) to look at the string as a debugging step.

Before you search through a string like this, you should analyze it carefully.

Sign up to request clarification or add additional context in comments.

1 Comment

added str_replace("\xc2\xa0", ' ',$str) and solved. thx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.