How find and replace a string in the HTML file

Discussion in 'Perl Misc' started by jussi, Oct 6, 2005.

  1. jussi

    jussi Guest

    hi gurus

    I need to replace some string in the html file but haven't manage to
    work it out.

    In a HTML file I have a string :

    ......<a href="javascript:CreateList(TopForm)"><img
    src="images/playselected.gif" bgcolor="#949494" align="right/"
    border="0"></a>
    ....


    Which I need to replace with this one:

    &nbsp;


    I have look for exsample HTML::parser but couldn't understand how it
    works !!

    So please, give me exsample code how to find a string and replace it.

    Thanks advance
    -Jussi
     
    jussi, Oct 6, 2005
    #1
    1. Advertising

  2. > hi gurus
    >
    > I need to replace some string in the html file but haven't manage to
    > work it out.
    >
    > In a HTML file I have a string :
    >
    > .....<a href="javascript:CreateList(TopForm)"><img
    > src="images/playselected.gif" bgcolor="#949494" align="right/"
    > border="0"></a>
    > ....
    > Which I need to replace with this one:
    >
    > &nbsp;


    I'm CERTAINLY NOT a guru but

    my $str = "Mary had a large lamb";

    $str = s/large/little/g;

    might get you started

    J
     
    Julia De Silva, Oct 6, 2005
    #2
    1. Advertising

  3. Sorry That's
    my $str = "Mary had a large lamb";
    $str =~ s/large/little/g;

    J
     
    Julia De Silva, Oct 6, 2005
    #3
  4. jussi wrote:
    > I need to replace some string in the html file but haven't manage to
    > work it out.
    >
    > In a HTML file I have a string :
    >
    > .....<a href="javascript:CreateList(TopForm)"><img
    > src="images/playselected.gif" bgcolor="#949494" align="right/"
    > border="0"></a>
    > ....
    >
    > Which I need to replace with this one:
    >
    > &nbsp;
    >
    > I have look for exsample HTML::parser but couldn't understand how it
    > works !!


    If you search this group, you'll find examples of how to use it.

    If the above is the only thing you want to replace, something like this
    may be sufficient:

    $html =~ s#<a\s+href.+?CreateList\(TopForm\).+?</a>#&nbsp;#is;

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 6, 2005
    #4
  5. jussi

    jussi Guest

    Thanks Gunnar, it work fine !

    But when I use the same method to find and replace next string:

    <a
    href="javascript:popUpPlayFile('./PlayFile.asp?E:\\video\\506-TEST-VIDEO.mpg@$$@506-SRI%CH20so-',1)">


    With this:
    <a ref file://LINK_TO_VIDEO >

    And I do it like this

    $html =~
    s#<a\s+href"javascript:popUpPlayFile.+?506-TEST-VIDEO.+?>img<#<a ref
    file://LINK_TO_VIDEO >#is;

    This doesn't work. Any help would be nice ..

    -Jussi
     
    jussi, Oct 7, 2005
    #5
  6. jussi wrote:
    > Thanks Gunnar, it work fine !


    What works fine? Please provide context when replying to a message, as
    is recommended in the posting guidelines for this group:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    (Those who may be able to reply don't usually access the group via Google.)

    > But when I use the same method to find and replace next string:
    >
    > <a
    > href="javascript:popUpPlayFile('./PlayFile.asp?E:\\video\\506-TEST-VIDEO.mpg@$$@506-SRI%CH20so-',1)">
    >
    > With this:
    > <a ref file://LINK_TO_VIDEO >


    Do you possibly mean

    <a href="file:///PATH_TO_VIDEO">

    > And I do it like this
    >
    > $html =~
    > s#<a\s+href"javascript:popUpPlayFile.+?506-TEST-VIDEO.+?>img<#<a ref

    -------------^---------------------------------------------^^^^

    Where is the equality sign?

    What's 'img<'?

    > file://LINK_TO_VIDEO >#is;
    >
    > This doesn't work. Any help would be nice ..


    You can help both yourself and us by checking your code _carefully_
    before asking hundreds of people for help.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 7, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. peter
    Replies:
    5
    Views:
    737
    Roberto Bonvallet
    Aug 23, 2006
  2. Alun
    Replies:
    3
    Views:
    4,618
    Masudur
    Feb 18, 2008
  3. Prasad S
    Replies:
    2
    Views:
    251
    Dr John Stockton
    Aug 27, 2004
  4. V S Rawat
    Replies:
    5
    Views:
    335
    Richard Cornford
    Jul 3, 2007
  5. loial
    Replies:
    8
    Views:
    147
    Emile van Sebille
    Mar 5, 2014
Loading...

Share This Page