Using php to execute javascript function

Hi,

I’m not a programmer, except for some basic html, but I want to modify a svg file from relative coordinates to absolute ones.
I’ve found a script but I don’t know what to do with it. I’ve read that I must call it from php but don’t know what to write in this file.
Maybe I have to enter my text of coordinates in php, then call the js function then write the new file, but I don’t know where to begin and where to end to do this whole task.
May I find some help here ?
Here is a sample of the javascript :

function pathToPoints( path ) {
var paths = path.split( /z|Z/ ), points = new Array();
for ( var i = 0; i < paths.length-1; i++ ) {
path = paths[i].split( /l|L/ );
path[0] = path[0].replace( /m|M/, ‘’ );
…/…
…/…
for ( var j in path ) {
path[j] = path[j].join( ‘,’ );
}
points[i] = path.join( ’ ’ );
}
return points;
}
<snip/>
Thanks

Phil

You can’t call JavaScript from PHP.

PHP runs on the server and generates the HTML for a web page. That HTML can have JavaScript attached to it.

The JavaScript itself should reference the parts of the HTML that the parts of the script need to be attached to. That way each language can be kept completely separate.

Hi Stephen,

Thanks for your response. I had a look in your js examples.
I’ve created an html document and a .js one. I’ve also created a txt file containing the coordinates I have to convert in absolute ones. In the path field of the js, I indicate the txt name… and then…how does it work? I understand that the html loads the js which will process the txt file but I don’t know how to execute this function and where the new file will be available.
my html :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Example 01</title>
</head>
<body>
<div id="ex"></div>
<script type="text/javascript" src="rel_to_absolute.js"></script>
</body>
</html>

my js :

// JavaScript Document
function pathToPoints( test.txt ) {
	var paths = path.split( /z|Z/ ), points = new Array();
	for ( var i = 0; i < paths.length-1; i++ ) {
		path = paths[i].split( /l|L/ );
		path[0] = path[0].replace( /m|M/, '' );
		for ( var j in path ) {
			path[j] = path[j].split( ',' );
			for ( var k in path[j] ) {
				path[j][k] = parseFloat( path[j][k] );
				if ( j != 0 ) {
					path[j][k] += path[j-1][k];
				}
			}
		}
		for ( var j in path ) {
			path[j] = path[j].join( ',' );
		}
		points[i] = path.join( ' ' );
	}
	return points;
}

I understand that the html loads the js which will process the txt file but I don’t know how to execute this function and where the new file will be available.
Maybe I should go farther in js learning, but I never (at this time) have to use js.

Where could I find a related example?

Thanks

Phil