file get contents - file_get_contents(): stream does not support seeking PHP
I'm trying to use file_get_contents() to grab only Name from fake name generator site(https://fakena.me/fake-name/), however I'm getting the following warning:
file_get_contents() stream does not support seeking
I dont need entire content of the page. I need only Name section in this site: https://fakena.me/fake-name/.
My code:
$name= file_get_contents('https://fakena.me/fake-name/', NULL, NULL, 849, 32);
Its working well in localhost, showing error only in live website.
Answer
Solution:
You can read about it in the documentation:
What you can do is use
substr
after what you retrive the contents of the page:Answer
Solution:
This is basically the offset issue in the latest versions
Here we need to change the $offset value from -1 t0 1
Answer
Solution:
Why are you scraping website? Lots of free APIs are available for fake name generator.
You will get output in JSON format. Decode it using json_decode() and use for your purpose and also it's fast as compared to scraping.
Optional Parameters
The number of names to return, between 1 and 500:
Limit results to the male or female gender:
Region-specific results:
Require a minimum number of characters in a name:
Require a maximum number of characters in a name:
For JSONP, specify a callback function to wrap results in: