You are not logged in.

#1 2009-02-24 06:01:39

pinchyfingers
Member
From: Bristol, PA
Registered: 2008-11-04
Posts: 46
Website

PHP troubles

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

#2 2009-02-24 07:06:28

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: PHP troubles

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

#3 2009-02-25 02:44:12

Varreon
Member
Registered: 2008-07-03
Posts: 95

Re: PHP troubles

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

#4 2009-02-27 03:35:28

pinchyfingers
Member
From: Bristol, PA
Registered: 2008-11-04
Posts: 46
Website

Re: PHP troubles

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

Board footer

Powered by FluxBB