...

View Full Version : Build Search and Replace Web form?



jimcj1301
12-06-2012, 01:36 AM
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)


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"


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

rnd me
12-06-2012, 06:42 AM
not 100% sure what you need, but hopefully you can modify this to work for you:


<!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

jimcj1301
12-07-2012, 05:15 AM
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


http://i50.tinypic.com/10nt1t1.jpg


I realllly appreciate your help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum