Avatar of KeterHD
KeterHDFlag for Israel

asked on 

Remove all HTML/XML tags from CSV file

Hola, everyone!

I've got myself a CSV file, of MySQL descent. Originally, the file was used as a DB for a website. For that reason, the text inside the table contains tons of HTML/XML characters intended to specify the location and design of the text on a page.

While it's all swell, now that I need to get just the text out of it, it's quite a nightmare. As there are hundreds of variations of design tags within the document, there is no way I could possibly remove them all.

Could you think of a way to strip the document of all tags? I found some solutions using PHP, however, I lack knowledge of it, hence I can do little to improve the situation.
PHPHTMLWeb Development

Avatar of undefined
Last Comment
KeterHD
Avatar of V4nP3rs13
V4nP3rs13
Flag of Bosnia and Herzegovina image

maybe you should use strip_tags(); function while exporting...

Here is an example:
$csvContent = 'blabla<tr><td>blabla</td></tr>";

$export = strip_tags($csvContent);

you can also exclude some html tags in second parameter of strip_tags(); like this:
strip_tags($csvContent, "<a><b><table>"); this means that <a>, <b> and <table> tags will stay unfiltered.
Avatar of mars-vie
mars-vie
Flag of Austria image

Avatar of KeterHD
KeterHD
Flag of Israel image

ASKER

Hey, mates.

@V4nP3rs13: As far as I understand, the strip_tags requires a variable. However, I've got 1600 separate lines of text that must remain separate. I obviously cannot create 1600 variables.

@mars-vie: I'm looking into it.
Avatar of V4nP3rs13
V4nP3rs13
Flag of Bosnia and Herzegovina image

Can you paste me the code. Which way of CSV exporting are you using ?? Do you use an array for that or something else ??
Avatar of KeterHD
KeterHD
Flag of Israel image

ASKER

No, no, you don't understand. I have no code. I just have this former-DB file from which I need to remove dozens of thousands of tags. The question is how.
ASKER CERTIFIED SOLUTION
Avatar of V4nP3rs13
V4nP3rs13
Flag of Bosnia and Herzegovina image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of KeterHD
KeterHD
Flag of Israel image

ASKER

Okay.

In order to execute it, I assume I have to run it on an IIS/Apache/whatever server?
Avatar of V4nP3rs13
V4nP3rs13
Flag of Bosnia and Herzegovina image

apache prefered :)
Avatar of KeterHD
KeterHD
Flag of Israel image

ASKER

Haha, I bet. Will get back to you.
Avatar of V4nP3rs13
V4nP3rs13
Flag of Bosnia and Herzegovina image

Does it work ??
Avatar of KeterHD
KeterHD
Flag of Israel image

ASKER

Sorry, it was late evening, mate. I'll let you know within a few hours.
Avatar of KeterHD
KeterHD
Flag of Israel image

ASKER

Okay, it doesn't work on my IIS server for some reason (no doubt, thanks to Symantec Endpoint Protection Manager installed on it). I'm installing XAMPP on a VM and will get back to you.
Avatar of KeterHD
KeterHD
Flag of Israel image

ASKER

Damn, I thought I was expected to see output in MSIE window, so I believed the script didn't work. It did, on both Apache and IIS, but with no result. The exported file is absolutely the same.

Allow me to post an example of single entry containing the tags. The situation is pretty similar accross all 6100 lines:

&lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt; &lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt; &lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt; &lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt; &lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt; &lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt;¿¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿¿, ¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿ ¿¿¿¿, ¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿, ¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿ ¿¿¿¿. ¿¿¿ ¿¿, ¿¿¿¿ ¿¿¿¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿¿¿ &quot¿¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿&quot, ¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿, ¿¿¿ ¿¿ ¿¿¿¿¿¿¿, ¿¿¿ ¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿. ¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿ ¿¿ ¿¿ ¿¿ ¿¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿-¿¿¿¿¿¿¿¿¿¿¿¿ ¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿, ¿¿¿ ¿¿ ¿¿ ¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿, ¿¿¿¿¿¿¿¿, ¿¿¿¿¿¿, ¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿, ¿¿¿¿¿¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿.&lt;/div&gt;  &lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt;¿¿¿¿¿¿¿ ¿¿¿¿¿¿, ¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿, ¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿¿¿¿-¿¿¿¿¿¿¿, ¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿ ¿¿¿¿¿¿. ¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿¿¿, ¿¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿ ¿¿¿¿ ¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿-¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿¿¿.&lt;/div&gt;  &lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt;¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿¿¿¿¿¿¿, ¿¿¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿ ¿¿ ¿&quot¿¿¿¿¿ ¿¿¿¿¿¿&quot ¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿, ¿¿¿¿¿¿¿ ¿¿¿¿¿, ¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿¿¿¿, ¿¿¿ ¿¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿.&lt;/div&gt;  &lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt;¿¿¿ ¿¿ ¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿¿¿¿ &quot¿¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿ - ¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿&quot. ¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿: (1) &quot¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿, 1914-1860&quot (1983); (2) &quot¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿&quot (1985); (3) &quot¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿-¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿ 1918-1855&quot (1987); (4) &quot¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿ 1948-1918&quot (1989); (5) &quot¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿ 1990-1948&quot (1991).&lt;/div&gt;  &lt;div dir=&quotrtl&quot style=&quotTEXT-ALIGN: right&quot&gt;¿¿¿¿ ¿¿¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿¿¿-¿¿¿¿¿¿ ¿¿ ¿¿¿¿¿¿¿, ¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿¿ ¿¿¿.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

Open in new window

Avatar of KeterHD
KeterHD
Flag of Israel image

ASKER

Oh, the question marks are supposed to be an RTL text, but I guess EE can't display those here.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo