Ask about general coding issues or problems here.
3 posts • Page 1 of 1
Help I have an html file, and in that html file I located the spot that I wish to insert text. The problem is that I endup overwritting html that is below that spot. How can I make it not write over other text, but rather just push it farther down so that it does not overwrite previous code. Thanks
Jabolin wrote:Help I have an html file, and in that html file I located the spot that I wish to insert text. The problem is that I endup overwritting html that is below that spot. How can I make it not write over other text, but rather just push it farther down so that it does not overwrite previous code. Thanks
from what you say, you have a spot in the html file. You need to find the text between the 2 spots (beginning and ending of the string) and then use the replace function to write the new text input in place.
You can do these two steps in the following way:
1) find the string to be replaced with the function "strpos ", check for details at http://www.php.net/manual/en/function.strpos.php
with this function you get the positions of those 2 spots. You then need to substract them and get the string in between with the function "substr" (again check foa mare details at http://www.php.net/manual/en/function.substr.php)
2) after that you have the string which you want to replace. At this point you use the the ereg_replace or eregi_replace according to whether you want the finding and replacement to be case sensitive or not. Check at http://www.php.net/manual/en/function.eregi-replace.php for more details.
One more point: Don;t forget to put in the string that will replace the original string the two spot points. It is a usual mistake and if you forget to do so, you will not be capable of replacing the strinf next time.
Hope it helps,
I could not get it to work quite that way. I ran into problems cause I figured that I would have to change the whole html document into one string, and then fix it afterwords--what a mess, and I could not see how to make that easy, so what I did was read one line at a time and if that was not the line that I wanted to replace I would print it to the new document, and then once I found the line I wanted to replace I would print that to the new document, and then go back to simply copying. This solved the problem. This also allows me to let the user preview the changes before actually re-writing the document. Thanks for pointing me in the right direction. Your help is greatly appreciated.
Who is online
Users browsing this forum: Bing [Bot] and 2 guests