Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Build Search and Replace Web form?

    I want to know how or what would be the best way to achieve the following.If im not in the correct forum im sorry, I thought Javascript would be the best way.

    I work with a large eCommerce company and we have to constantly replace images with new images and then clear the cache using a pre-made template. I'll show a small example of the template it's a *.txt file template that I use for refreshing content on "Akamai edge control"

    There is about 100 different lines in the text file each a little different but they all contain to sets of generic variables.

    (example excerpt below - using the PHP box to show my sample but its just links)

    PHP Code:
    http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image250 
    http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image500 
    http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image800 
    http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image1000 
    That is just an example of what it looks like in the text file. The thing we do is open the file with Notepad and press Ctrl+h and the replace box pops up. I put in a number could be i.e. "123456" to replace the xxxxxx but I then have to go back to the number and manually change it to "123000" mind you we are only making changes to the xxxxxx and the zzzzzz. They are just place holders. So my end result would be like this...

    Ps. on the zzzzzz it always ends with "000"

    PHP Code:
    http://www.mysite.com/file/folder/blah/123456/_something_else here/123000/image250 
    http://www.mysite.com/file/folder/blah/123456/_something_else here/123000/image500 
    http://www.mysite.com/file/folder/blah/123456/_something_else here/123000/image800 
    http://www.mysite.com/file/folder/blah/123456/_something_else here/123000/image1000 
    My main question is... is there already some sort of program that can run this process a bit more automatically by just selecting my template file and pasting in my only "123456" and getting all the lines the change while adding the zzzzzz with the zero's also.

    I'm trying to eliminate a ton of work and make the process more efficient. My example of "123456" could also be up to "1234567". Maybe even pasting in more then one number separated with commas kind of like "123456,123457,123458" then it runs sample process generating a block of text for each number like it was found and replaced manually.

    Ideally I would like to just have a web based form like the image mock up below to perform the task, unless there is another way without installing software on over 1000 computers. Hope this make sense. Thanks in advance for any input.

    http://i.stack.imgur.com/6Kc5B.jpg

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    not 100% sure what you need, but hopefully you can modify this to work for you:

    Code:
    <!DOCTYPE html>
    <html>
      <head>
        <title>file reps</title>
    
    </head>
    <body style="zoom: 1.5"> <center>
    	<input type="file" onchange='readText(this)' /> <br />
    
    	<textarea rows=10 cols=84 id="txtReps">123456, 123000</textarea> <br />
    		<button onclick="rip()">run script</button>
    		<button onclick="output.value=output.defaultValue;">reset</button>
    	<br />
    
    	<textarea rows=10 cols=84 id="output">http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image250  
    http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image500  
    http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image800  
    http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image1000  </textarea>
    	
    
    	
        <script type="text/javascript">
    
    		var reader = new FileReader();
    
    		function rip(e) {  
    			var out=(e && e.target && e.target.result) || output.value ;
    			var reps=txtReps.value.split(/\s*,\s*/);
    			
    			output.value= out.split("\n").map(function(a){
    				return a	.split("xxxxxx").join(reps[0])
    						.split("zzzzzz").join(reps[1]);
    			}).join("\n");
    		}
    					
    
    		function readText(that){
    
    			if(that.files && that.files[0]){
    				var reader = new FileReader();
    				reader.onload = rip;
    				reader.readAsText(that.files[0]);
    			}//end if html5 filelist support
    		} 
    
    </script>
    
    </center>  </body>
    </html>
    i budgeted 15 mins, spent 14m37s
    Last edited by rnd me; 12-06-2012 at 05:47 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    jimcj1301 (12-07-2012)

  • #3
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    wow, almost exactly what I was looking for. I made a new image sample that might show a little bit more clear what I want it to do. Not sure what to tweak to get it to split the xxxxxx numbers and add the 000's

    I just want to be able to add " 123456,123457,123458,123459, etc...endless" and then get the output to automatically take each of those numbers and plug them into the "xxxxxx" while also replacing the last three numbers with 000 and plugging into the "zzzzzz"

    Maybe even a COPY button at the bottom that will select the output script and/or copy





    I realllly appreciate your help.


  •  

    Posting Permissions

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