Inserting code into a text file or deleting unwanted code?

Posted on 2003-03-27
Medium Priority
Last Modified: 2006-11-17
I have some code I have grabbed from a news site. I need to take that code and either:

1- Delete the unwanted HTML from around the headlines I have grabbed or
2- Add beginning and ending tags to the code so I can grab it again and just display what is between the two tags I just inserted.

All I need to know is how to either insert code into a text file via PHP, or how to delete unwanted lines of code. Any help or direction to where I can find help would be greatly appreciated.
Question by:Bice
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

girish_nair earned 500 total points
ID: 8222444

try these:-
1) read the file into a variable(either string [fread] or array [file])
2) parse through the contents of this variable and grab the required thing (useing string functions)
OR replace the unwanted content with blank (use eregi_replace("pattern","",$variable)
3) now write the new content to the file


Author Comment

ID: 8222637
Thanks, I will look into this and hopefully get it to work. I just needed a direction to go towards.

Expert Comment

ID: 8223540

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question