0

I currently tried to get the plain text from another php file line by line, however it seems that it doesnt understand the encoding.

  $parsedFile= file_get_contents('source.php', true);
  $text= '';

  foreach(preg_split("/((\r?\n)|(\r\n?))/", $parsedFile) as $line){
    $text.= $line;
  }

  echo $parsedFile;

How can I extract the text from a php file by using phps in built functions and classes?

1 Answer 1

1

There is the built-in PHP function file() returning an array with an entry for each line, which should be exactly what you are looking for:

$linearray = file("source.php");

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

12 Comments

Holy crap, there is a function for everything in php. I was already scared that id have to create a byte stream and parse all the characters. I didnt really find any specifications for the php file so...
Is there any content in source.php and is this file in the same directory as the code is?
Sorry it takes a while for my question to be updated. Ill place code in here until then: jsfiddle.net/kva3ok5s
Indeed, I got a php script inside there. I do get the content as an array but I just cant access it. When doing it inside a loop the output is just empty but when accessing an item manually instead of using the $i variable it works for that one item. It is weird.
|

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.