Announcement

Collapse
No announcement yet.

use filename to create variables

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • use filename to create variables

    I want to use filename to create variables.

    Filename look likes this

    name - surnames dateborn placeborn + datedied placedied.jpg
    Aerts - Adolf Herman 01 mei 1944 Liedekerke + 20 maa 1945 Liedekerke.jpg

    This is wath i want
    var1 = name
    var2 = surnames
    var3 = dateborn
    var4 = placeborn
    var5 = datedied
    var6 = placedied

  • #2
    What you want to do cannot be done with HTML alone. I've moved the thread over to Server-Side Programming for you. Someone there will have a better idea of what you need.
    Cat-herder Extraordinaire

    Comment


    • #3
      That would be rather difficult as the file name is a image for one and there are spaces all in the filename with no ending to each section. If you did something like this

      Aerts - Adolf Herman _01 mei 1944_ Liedekerke _20 maa 1945_Liedekerke.jpg

      Consistency is your best bet here. This way I have used the underscore in the file name, then we can split that up to whatever you like. Is it possible to have the file name like that? You could even use a hyphen instead of underscores
      Have a Script or Snippet you want to share?

      WWW Standards: HTML 4.01,
      HTML 5, CSS2.1, CSS3, XHTML 1.0
      PHP Standards: PHP Standards

      Comment


      • #4
        The underscore in the file name is possible.

        Comment


        • #5
          "we can split that up to whatever you like".
          How?

          Comment


          • #6
            What server side language would you like to use?

            PHP it would be something like this

            PHP Code:
            $Filename "Aerts_Adolf Herman _01 mei 1944_ Liedekerke _20 maa 1945_Liedekerke.jpg";
            $pieces explode("_"$Filename );
            echo 
            $pieces[0] ; // pieces 
            echo $pieces[1]; // surnames
            echo $pieces[2]; // dateborn
            echo $pieces[3]; // placeborn
            echo $pieces[4]; // datedied
            echo substr($pieces[5], 0, -4); // placedied - also strips off .jpg 
            Of course there are many methods on how to do it depending on where it is coming from.
            Last edited by scoutt; 07-29-2015, 09:42 AM.
            Have a Script or Snippet you want to share?

            WWW Standards: HTML 4.01,
            HTML 5, CSS2.1, CSS3, XHTML 1.0
            PHP Standards: PHP Standards

            Comment


            • #7
              This Might Help...

              Filename look likes this

              name - surnames dateborn placeborn + datedied placedied.jpg
              Aerts - Adolf Herman 01 mei 1944 Liedekerke + 20 maa 1945 Liedekerke.jpg

              This is wath i want
              var1 = name
              var2 = surnames
              var3 = dateborn
              var4 = placeborn
              var5 = datedied
              var6 = placedied
              "we can split that up to whatever you like".
              How?
              Code:
              <!DOCTYPE html>
              <html><head>
                <script>
                 function retVal(filename) { var ret="";	
              	
              	filename=filename.replace(/ /ig,'_');
              	filename=filename.replace(/\n/ig,'');		
              	
              	var var1 = filename.split('-')[0].replace(/_/ig,'');
              	var var2 = filename.split('')[0].split('-')[1].replace(/_/ig,'');
              	var var3 = filename.split('+')[0].split('')[1].split('_')[1].replace(/_/ig,'');
              	var var4 = filename.split('+')[0].split('')[1].split('_')[2].replace(/_/ig,'');
              	var var5 = filename.split('+')[1].split('.')[0].split('_')[1].replace(/_/ig,'');
              	var var6 = filename.split('+')[1].split('.')[0].split('_')[2].replace(/_/ig,'');
              	
              	ret += 'var1 = ' + var1 + '<br/>';
              	ret += 'var2 = ' + var2 + '<br/>';
              	ret += 'var3 = ' + var3 + '<br/>';
              	ret += 'var4 = ' + var4 + '<br/>';
              	ret += 'var5 = ' + var5 + '<br/>';
              	ret += 'var6 = ' + var6 + '<br/>';
              	
              	return ret;
              	
                 };
                </script>
              </head><body>
              
              	<div id='origin'>name - surnames  dateborn placeborn + datedied placedied.jpg</div>
              	<hr/>
              	<div id='output'></div>
              
              <script>
              	var convertedValue = retVal('name - surnames  dateborn placeborn + datedied placedied.jpg');
              	document.getElementById('output').innerHTML=convertedValue;
              </script>
              
              </body></html>
              Last edited by Structure; 08-03-2015, 10:46 PM.

              Comment


              • #8
                Test 1:
                name - surnames dateborn placeborn + datedied placedied
                Aerts - Adolf Herman 01 mei 1944 Liedekerke + 20 maa 1945 Liedekerke

                Result:
                var1 = Aerts
                var2 = AdolfHerman
                var3 = 01
                var4 = mei
                var5 = 20
                var6 = maa

                Test 2:
                name - surnames dateborn placeborn + datedied placedied
                Aerts - Adolf Herman 01mei1944 Liedekerke + 20maa1945 Liedekerke

                var1 = Aerts
                var2 = AdolfHerman
                var3 = 01mei1944
                var4 = Liedekerke
                var5 = 20maa1945
                var6 = Liedekerke

                Spaces in date seems to be a problem.
                => I can use format DDMMMJJJJ in file name.

                Spaces between surnames seems to be a problem.

                Comment


                • #9
                  If you use mine it doesn't care about spaces. file names with odd characters in them is never a good idea.
                  Last edited by scoutt; 09-22-2015, 11:49 AM.
                  Have a Script or Snippet you want to share?

                  WWW Standards: HTML 4.01,
                  HTML 5, CSS2.1, CSS3, XHTML 1.0
                  PHP Standards: PHP Standards

                  Comment


                  • #10
                    Ok

                    I can use format DDMMMJJJJ
                    I would suggest that.

                    Spaces between surnames seems to be a problem.
                    filename=filename.replace(/ /ig,'_');
                    Reason:
                    Code:
                    name - surnames  dateborn placeborn + datedied placedied
                    dateborn placeborn
                    Solution:
                    name - surnames dateborn placeborn + datedied placedied
                    HTML Code:
                    <!DOCTYPE html>
                    <html><head><meta charset='UTF-8'>
                      <script>
                       function retVal(filename) { var ret="";		
                    
                    	filename=filename.replace(/\n/ig,'');
                    		
                    	var var1 = filename.split('-')[0];
                    	var var2 = filename.split('')[0].split('-')[1];
                    	var var3 = filename.split('+')[0].split('')[1].trim().split(' ')[0];
                    	var var4 = filename.split('+')[0].split('')[1].trim().split(' ')[1];
                    	var var5 = filename.split('+')[1].trim().split(' ')[0];
                    	var var6 = filename.split('+')[1].trim().split(' ')[1];
                    	
                    	ret += 'var1 = ' + var1 + '<br/>';
                    	ret += 'var2 = ' + var2 + '<br/>';
                    	ret += 'var3 = ' + var3 + '<br/>';
                    	ret += 'var4 = ' + var4 + '<br/>';
                    	ret += 'var5 = ' + var5 + '<br/>';
                    	ret += 'var6 = ' + var6 + '<br/>';	
                    	
                    	return ret;
                    	
                       };
                      </script>
                    </head><body>
                    
                    	<div id='origin'>name - sur names  dateborn placeborn + datedied placedied</div>
                    	<hr/>
                    	<div id='output'></div>
                    
                    <script>
                    	var convertedValue = retVal(document.getElementById('origin').innerHTML);
                    	document.getElementById('output').innerHTML=convertedValue;
                    </script>
                    
                    </body></html>
                    http://www.w3schools.com/jsref/jsref_split.asp

                    Your filename string structure should be something like this:
                    name ~ sur names ~ date born ~ place born ~ date died ~ place died

                    Reason:
                    Characters used to split a string are not allowed in the array value.

                    Example: [1] ~ [2] ~ [3] ~ [4] ~ etc...
                    name ~ sur names ~ date ~ born ~ place born
                    name ~ sur names ~ date born ~ place born

                    The third value in the array will be different.

                    i.e.
                    $Filename = "Aerts_Adolf Herman _01 mei 1944_ Liedekerke _20 maa 1945_Liedekerke.jpg";
                    $pieces = explode("_", $Filename );
                    Last edited by Structure; 09-20-2015, 05:02 PM.

                    Comment

                    Working...
                    X