Results 1 to 4 of 4

Thread: How to avoid/get rid of code duplication?

  1. #1
    Registered User
    Join Date
    Aug 2003
    Location
    Somewhere:D.
    Posts
    312
    Thanks
    12
    Thanked
    2 times in 2 posts
    • Cuffz's system
      • Motherboard:
      • Foxconn
      • CPU:
      • Core 2 Quad 8200+
      • Storage:
      • 3+ TB
      • Operating System:
      • Windows Seven
      • Monitor(s):
      • 24" 1920 x 1080
      • Internet:
      • O2 8mb. ADSL2+

    Question How to avoid/get rid of code duplication?

    Hi,

    Explanation 1.


    I have many links to many html files but the html files are all the same except for one variable.

    How can I make the links link to one piece of code (html) and insert the variable into the appropriate place in that code instead of the above situation?

    Explanation 2.


    I have 100s of files with the following code in:

    <object codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab" height="396" width="704" classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616"><param name="autoplay" value="false"><param name="src" value="http://video.stage6.com/000000/.divx" /><param name="custommode" value="Stage6" /><param name="showpostplaybackad" value="false" /><embed type="video/divx" src="http://video.stage6.com/000000/.divx" pluginspage="http://go.divx.com/plugin/download/" showpostplaybackad="false" custommode="Stage6" autoplay="false" height="376" width="704" /></object>

    I want to have one copy of that code, not 100s
    I want the link to insert the desired variable in this section of the code here:
    <param name="src" value="http://video.stage6.com/000000/.divx" />
    The variable is the "0000000" bit.

    Rather than link to a html file with a copy of that code and variable in./ link to a duplicate of the code with changed variable.

    I have found a way to move all the duplicates of the code into one html file with an ajax pagination script.. however, now I need a way around this code duplication.


    Thanks!

  2. #2
    Ah, Mrs. Peel! mike_w's Avatar
    Join Date
    Oct 2003
    Location
    Hertfordshire, England
    Posts
    3,326
    Thanks
    3
    Thanked
    9 times in 7 posts

    Re: How to avoid/get rid of code duplication?

    The easiest way is probably just to use a server side language, such as PHP or ASP, and then process the variables via GET i.e. use URLs such as index.php?foo=123. In PHP, you'd have something like:

    echo '<param name="src" value="http://video.stage6.com/' . $_GET['video'] . '/.divx" />';

    although you'd probably want to check that the variable is valid before inserting it.

    You can use mod rewrite with Apache to turn these into 'nice' URLs e.g. Have /contactus/ point to /index.php?page=contactus

    I've never really used Javascript before, but I'd imagine you could do something similar with it.
    "Well, there was your Uncle Tiberius who died wrapped in cabbage leaves but we assumed that was a freak accident."

  3. Received thanks from:

    Cuffz (29-12-2007)

  4. #3
    Comfortably Numb directhex's Avatar
    Join Date
    Jul 2003
    Location
    /dev/urandom
    Posts
    17,074
    Thanks
    228
    Thanked
    1,026 times in 677 posts
    • directhex's system
      • Motherboard:
      • Asus ROG Strix B550-I Gaming
      • CPU:
      • Ryzen 5900x
      • Memory:
      • 64GB G.Skill Trident Z RGB
      • Storage:
      • 2TB Seagate Firecuda 520
      • Graphics card(s):
      • EVGA GeForce RTX 3080 XC3 Ultra
      • PSU:
      • EVGA SuperNOVA 850W G3
      • Case:
      • NZXT H210i
      • Operating System:
      • Ubuntu 20.04, Windows 10
      • Monitor(s):
      • LG 34GN850
      • Internet:
      • FIOS

    Re: How to avoid/get rid of code duplication?

    any page that won't work without javascript is broken

    server-side is the way here

  5. #4
    Registered User
    Join Date
    Aug 2003
    Location
    Somewhere:D.
    Posts
    312
    Thanks
    12
    Thanked
    2 times in 2 posts
    • Cuffz's system
      • Motherboard:
      • Foxconn
      • CPU:
      • Core 2 Quad 8200+
      • Storage:
      • 3+ TB
      • Operating System:
      • Windows Seven
      • Monitor(s):
      • 24" 1920 x 1080
      • Internet:
      • O2 8mb. ADSL2+

    Re: How to avoid/get rid of code duplication?

    Thanks for replies :] server side it is then..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mice - getting rid and keeping rid
    By Damo1176 in forum General Discussion
    Replies: 22
    Last Post: 12-07-2007, 10:06 PM
  2. DreamHost 555 Promo Code - 5 domains, 5Tb of bandwidth, 500Gb of storage for life
    By ChristopherW in forum Retail Therapy and Bargains
    Replies: 18
    Last Post: 30-05-2007, 09:24 PM
  3. HELP: MAC Code Length?
    By top_caty in forum Networking and Broadband
    Replies: 3
    Last Post: 09-03-2007, 01:44 AM
  4. How long does it take for my ISP to get me a MAC code from BT???
    By malice19 in forum Networking and Broadband
    Replies: 13
    Last Post: 14-01-2007, 08:38 AM
  5. Linux code help!
    By nvening in forum Software
    Replies: 18
    Last Post: 26-02-2005, 12:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •