You are not logged in.
Pages: 1
I have to write this script in PHP and part of it is to take two strings and print them both out with the differences highlighted. I'm having many troubles getting the arrays in PHP to work for me.
Does anyone have any suggesstions about how to approach this problem.
Offline
I'm not sure how I would go about tackling that problem, although I seem to recall some built in PHP features that might help you compare strings ( http://php.net/similar_text ), or they might not help at all. But you say you're having troubles getting PHP arrays working for you? What troubles are you having?
Offline
You mean, like this:
function diffstr($a, $b){ //put longer string in $a
for($x=0;$x<strlen($a);$x++){
if($a[$x]!=$b[$x])
print "<div class=\"color\">$a[$x]</div>";
}
}
Of course, have some bounds checking so that you arent reading beyond the shorter string.
Offline
I had to translate a script from python into PHP, so I already had the algorithm I needed, I was just struggling getting the PHP code to work right. That was my first time working in PHP, but everything is working ok now, thankfully.
Offline
Pages: 1