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:



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!

Recommended Answers

All 8 Replies

I've tried that, could you give me an example what you mean?

$temp = "MyObject.MyFunction(doSomething)";
echo substr($temp,9);

Could you please explain what the 9 does?

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.

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.

try this

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">

	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 



hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.