Thread: Find & Replace

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    30
    Rep Power
    6

    Find & Replace


    Hi,
    I've more than 558 fields to update with diffrent names & id's.
    for eg:

    Code:
    <cfinput type="text" name="ShoulderFlexSL" id="ShoulderFlexSL" tabindex="10" size="8" maxlength="50" >
    <cfinput type="text" name="ShoulderFlexSR" id="ShoulderFlexSR" tabindex="20" size="8" maxlength="50" >
    <cfinput type="text" name="ShoulderFlexRML" id="ShoulderFlexRML" tabindex="30" size="8" maxlength="50" >
    <cfinput type="text" name="ShoulderFlexRMR" id="ShoulderFlexRMR" tabindex="40" size="8" maxlength="50" >
    <cfinput type="text" name="ShoulderFlexSL" id="ShoulderFlexSL" tabindex="10" size="8" maxlength="50" >
    I am wondering is there a way I can use FIND & REPLACE -offcourse with some regex to accomplish this task & add another value attribute in those inputs with same name & id attributes value.

    <cfinput type="text" name="ShoulderFlexSL" id="ShoulderFlexSL" tabindex="10" size="8" maxlength="50" value="#ShoulderFlexSL#">
    <cfinput type="text" name="ShoulderFlexSR" id="ShoulderFlexSR" tabindex="20" size="8" maxlength="50" value="#ShoulderFlexSR#">
    <cfinput type="text" name="ShoulderFlexRML" id="ShoulderFlexRML" tabindex="30" size="8" maxlength="50" value="#ShoulderFlexRML#">
    <cfinput type="text" name="ShoulderFlexRMR" id="ShoulderFlexRMR" tabindex="40" size="8" maxlength="50" value="#ShoulderFlexRMR#">

    Any comments would be deeply appreciated.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    Brisbane, Australia
    Posts
    20
    Rep Power
    0
    Well you could use a regular expression such as:
    Code:
    Find: (<cfinput.+?name="([a-z]+)".+?id="\2".+?)(?=>)
    Replace: $1value="#$2#">
    You could either create a small script, or do it in an advanced text editor. Since I currently have my PHP IDE open, I did it in PHP as an example.

    PHP Code:
    $string '<cfinput type="text" name="ShoulderFlexSL" id="ShoulderFlexSL" tabindex="10" size="8" maxlength="50" >
    <cfinput type="text" name="ShoulderFlexSR" id="ShoulderFlexSR" tabindex="20" size="8" maxlength="50" >
    <cfinput type="text" name="ShoulderFlexRML" id="ShoulderFlexRML" tabindex="30" size="8" maxlength="50" >
    <cfinput type="text" name="ShoulderFlexRMR" id="ShoulderFlexRMR" tabindex="40" size="8" maxlength="50" >
    <cfinput type="text" name="ShoulderFlexSL" id="ShoulderFlexSL" tabindex="10" size="8" maxlength="50" >'
    ;

    echo 
    '<pre>',
        
    htmlentities(preg_replace('/(<cfinput.+?name="([a-z]+)".+?id="\2".+?)(?=>)/i''$1value="#$2#"'$string)),
        
    '</pre>'
    Produces:
    Code:
    <cfinput type="text" name="ShoulderFlexSL" id="ShoulderFlexSL" tabindex="10" size="8" maxlength="50" value="#ShoulderFlexSL#">
    <cfinput type="text" name="ShoulderFlexSR" id="ShoulderFlexSR" tabindex="20" size="8" maxlength="50" value="#ShoulderFlexSR#">
    <cfinput type="text" name="ShoulderFlexRML" id="ShoulderFlexRML" tabindex="30" size="8" maxlength="50" value="#ShoulderFlexRML#">
    <cfinput type="text" name="ShoulderFlexRMR" id="ShoulderFlexRMR" tabindex="40" size="8" maxlength="50" value="#ShoulderFlexRMR#">
    <cfinput type="text" name="ShoulderFlexSL" id="ShoulderFlexSL" tabindex="10" size="8" maxlength="50" value="#ShoulderFlexSL#">

    Comments on this post

    • ManiacDan agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    30
    Rep Power
    6
    shivercube,
    you are one smart fellow I do appreciate your help & again can't thx ya enough for that..

IMN logo majestic logo threadwatch logo seochat tools logo