Zenan Plains - Site Discussion > General Discussion

Text formatting

(1/2) > >>

ZeaLitY:
I'm trying to replace all instances of <p> with a
line break. Unfortunately, when I paste the instance of such into textpad, it comes out as /n, and does nothing. Is it possible to do this? I'm trying to format the encyclopedia for phpbb.

Ramsus:
Now that you have Perl installed, you can do the following:

Create a folder to work in. Copy and paste all of the files you want to edit into this folder, making sure nothing else is there. Now then, use Notepad to create a new file with the following text:


--- Code: ---
perl -i.bak -p -e 's/<p.*?>/\n/g; s/<\/p.*?>//g;' *.txt

--- End code ---


And save it in that folder as htmltotxt.bat. The *.txt means edit all files that have a .txt extension in the current folder.

Then double click it. The folder should now be filled with .bak backups of the original files.

The .txt files should now be stripped of the <p> and </p> tags. I'll explain what the 's/<p.*?>/\n/g; s/<\/p.*?>//g;' means later. It's what's called a regular expression (or regex).

You can also use:


--- Code: ---
s/<br.*?>/\n/g;

--- End code ---


To replace <br>, <br /> and <br anything> with linebreaks.

So in the end, you'd want to use a .bat file with:

--- Code: ---
perl -i.bak -p -e 's/<p.*?>/\n/g; s/<\/p.*?>//g; s/<br.*?>/\n/g;' *.txt

--- End code ---


EDIT: I'll also teach you how to write your own Perl scripts (.pl) later, instead of using .bat files that call Perl from the commandline. This will allow you to do a lot more.

ZeaLitY:
Access Denied?

Ramsus:
Is that supposed to be an error? If so, are the files being used by another program? Did you put them and the .bat file in the same folder by themselves?

Can you please be more detailed? What did you do exactly? Where did it say Access Denied? Was it a dialog box? Was there anything else?

ZeaLitY:
I received that when trying the first string. When I tried the third, complete line, I received 'File not Found.' I have followed instructions as given.

Navigation

[0] Message Index

[#] Next page

Go to full version