Page 1 of 1

Deleting hyperlink(s) in a string of code source [SOLVED]

Posted: Tue Apr 08, 2014 5:52 pm
by atout66
Hi to all,

I'm trying to code a script to remove hyperlinks in a code source I uploaded. But I don't know what's the best approach.
After the use of a lineOffset(), I get a string in a var I want to clean. So I've a list of tag to remove and that's OK.

Code: Select all

put "<li>" , "<i>" , "<b>" , "</b>" , "</i>" , "</li>" , "&#160;" , "</span>" into theTagsToRemove
I run a repeat loop and clean all that tags from the var. But what about links and <span> tag ?
Do you know a tutorial somewhere about that ? I made a search on the forum but it says "No suitable matches were found ."

Kind regards, Jean-Paul.

Re: Deleting hyperlink(s) in a string of code source

Posted: Tue Apr 08, 2014 6:49 pm
by atout66
Here is what I code:

Code: Select all

get offset(aa,theLineToDealWith) -- search  aa = "<a href=" in the string theLineToDealWith
   if IT > 0 then -- there is a link(s)
      put IT into laPrimPos -- position of char  "<" in the string <theLineToDealWith>
      get offset(">",theLineToDealWith)
      delete char laPrimPos to IT of theLineToDealWith                         
   end if
It's OK, for one link only in the string, as I remove prior the tags "</a>".

Any idea how this script could be improved to continu if more links are in the string ?

Kind regards, Jean-Paul.

Re: Deleting hyperlink(s) in a string of code source

Posted: Tue Apr 08, 2014 7:08 pm
by Thierry
atout66 wrote:Here is what I code:

Code: Select all

get offset(aa,theLineToDealWith) -- search  aa = "<a href=" in the string theLineToDealWith
   if IT > 0 then -- there is a link(s)
      put IT into laPrimPos -- position of char  "<" in the string <theLineToDealWith>
      get offset(">",theLineToDealWith)
      delete char laPrimPos to IT of theLineToDealWith                         
   end if
It's OK, for one link only in the string, as I remove prior the tags "</a>".

Any idea how this script could be improved to continu if more links are in the string ?
Bonsoir Jean-Paul,

Here is an old post which does the opposite of what you want :)
But this could may be help you to go further...

http://forums.runrev.com/phpBB2/viewtop ... 462#p89699

What you can do is keep the regex I did write, and use the replacetext().

Regards,

Thierry

Re: Deleting hyperlink(s) in a string of code source

Posted: Tue Apr 08, 2014 7:26 pm
by jacque
I cheat and let the engine do it. It usually works:

Code: Select all

set the htmltext of fld "temp" to tHTML
get the text of fld "temp"

Re: Deleting hyperlink(s) in a string of code source

Posted: Tue Apr 08, 2014 7:42 pm
by atout66
Merci Thierry. I tried to deal with your function but I went into an infinite loop :roll:
May be I should wait 'till tomorrow...

Kind Regards, Jean-Paul.

Re: Deleting hyperlink(s) in a string of code source

Posted: Tue Apr 08, 2014 7:47 pm
by Thierry
atout66 wrote:Merci Thierry. I tried to deal with your function but I went into an infinite loop :roll:
May be I should wait 'till tomorrow...
with replaceText() you don't need the loop!
May be worth checking the dictionary :roll:

Otherwise, as you want to get rid of *all* tags,
try jacque's solution. I don't know if it works for all case,
but I have a strong tendancy to trust Jacque statements :)

Regards,
Thierry

Re: Deleting hyperlink(s) in a string of code source

Posted: Tue Apr 08, 2014 7:55 pm
by atout66
Oui Thierry, c'est exact, and thanks to Jacqueline. Very interresting approach.
I can get the string in a "temp" field and now I expect to play with the properties of this field "temp" to see if I can remove the underline text, the color and so on...

Kind regards, Jean-Paul.

Re: Deleting hyperlink(s) in a string of code source

Posted: Tue Apr 08, 2014 8:06 pm
by atout66
Ah ! Victoire :!:
The most easiest way to transform the color and underline text, in my case

Code: Select all

set the htmltext of fld "temp" to theLineToDealWith -- remove the links and <span> tags, every thing
put fld "temp" into myVarTmp -- clear the all formatting; color, underline, bold !
put myVarTmp into fld "leFinalTxt" -- retrieve the original text  

Again, thanks a lot Jacqueline and to all of you.

Kind regards, Jean-Paul.