1

I want to use php's strip tags in a bash script. I figured I could just cat the html file I want to use and use that input and pipe it into php and then pipe that into something else (sed). Is that possible? I'm not sure exactly how to pipe the output of file.html into the strip_tag function...maybe put it all in a variable? I want the following to keep just the anchor tags...in the following I put in dummy text for strip_tags string because I didn't know how to pipe file.html in:

cat file.html | php strip_tags("<p><a href='#'>hi</a></p>",'<a>') > removed_tags.html

2 Answers 2

1

You can read from STDIN in PHP using the stream URI php://stdin. As for executing it, you'll also need to quote the PHP code and use the -r option, as well as echoing the result. So here's the fixed script:

cat file.html | php -r "echo strip_tags(file_get_contents('php://stdin'), '<a>');" > removed_tags.html
Sign up to request clarification or add additional context in comments.

Comments

0

Reading from stdin in PHP and writing a php script without a file are possible, but it's way more trouble than just writing a file like

<?php echo strip_tags(file_get_contents($argv[1]), '<a>');

...

$ php that-file.php file.html > removed_tags.html

Comments

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.