Monday, December 24, 2007

SED: Converting carat symbols to HTML special characters

Goal: Show HTML and PHP code, rather than have it interpreted by the web browser.

Using a GNU or Unix command line, myWebpage.html is a regular fully working HTML web page, here is the command:

sed -e 's/\</\&#60;/g' -e 's/\>/\&#62;/g' myWebpage.html > newWebpage.html

Bash Program To Convert Tags to Special Characters
#!/usr/bin/env bash
echo  "lancemiller777@gmail.com"
echo "Argument 1 is file with html tags"
echo "sed -e 's/\</\&#60;/g' -e 's/\>/\&#62;/g' \${1}"
sed -e 's/\</\&#60;/g' -e 's/\>/\&#62;/g' ${1}

No comments: