Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl to php conversion with =~& !~

Status
Not open for further replies.

j0nxuser

Technical User
May 4, 2003
31
0
0
US
New to php5 and trying to figure out how to take a perl do/until loop (with like, eq and ne) and convert it to a php do/while loop.


do {
stuff;
more stuff;
}
until ((($title =~ /$level/i) && ($uid ne $rep)) ||
($top==1) ||
(($level eq "") && ($uid ne $rep)));



Not sure how to rewrite the perl until to php while and easily translate my like, not equal and equal.

I've been trying to play with strpos and preg_match and just not seeing it.

Any help/direction would be appreciated.

Thank you!
Mark

 
like is equivalent to stristr or strstr (case sensitive)

== is equivalent to === for numerics. but the == and === can be used in php for all variable types. === means == PLUS type equality.

ne is equivalent to != or !== (depending on type equivalency)

do ... until would be equivalent to do ... while but of course the condition would be reversed in logic.

the OR operator is || and the AND operator is &&

so translated your condition set would be

Code:
(
	(	(	stristr($level, $title) 
			&& 
			$uid != $rep
		) 
		||
		$top === 1
	) 
	||
		(
			empty($level) 
			&&
			$uid != $rep
		)
);

you could have used $level == "" as an alternative to empty(). empty() also tests to see whether the variable is set and whether it is null.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top