0

Hello, I've been studying PHP for a while now, and am tackling my biggest project so far. I need to parse python code (which I'm already doing) and color code it. I need to get a word RIGHT before the ( symbol. I've tried just about everything, and can't get it to work! Basically I need to parse like below:

Python:

MyObject.MyFunction(doSomething)

but in PHP I want to get MyFunction ONLY. Because I'm coloring functions, I don't wanna color the object or class, or the variables. Only the function, so I figure in theory i need to find the ( and somehow go back one word in the string.

It seems so simple, but none of the commands I've tried have worked, and I can't find anything online!

3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by vaultdweller123
0

But that's not what I originally wanted :/

I need to make it dynamic. So if my code is 1,000 lines long and the function() is on the 778th line 3 words in it can still color code it.

0

im just giving you the way how to do it through substr() to get just function part... you must discover in your own alogorithm on how to dynamically assign correct substr() start point and end point. Other way is regular expression. still you have to think of your own algorithm for such complex problem.

0

try this

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

	var str, regx, res;
	str = "ehad wajdawid  ajdka ada MyObject.samplefunc(val1,val2) dwadwa adwadwadawda";
	regx = /(MyObject.)+(\w+)+(\()+([\w+\,]*)+(\))/gi;
	res = str.match(regx);
	alert(res); // test the result 


});



</script>
</head>
<body>
</body>
</html>

hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.