desithugg Posted August 15, 2008 Share Posted August 15, 2008 Hi, I'm trying to convert a function someone wrote for me in PHP a while back which returns the text between two objects in an array. For example. text="[saad]hello[/saad]sffsad90aa89a8da[saad]bye[/saad]"; found=findText("[saad]","[/saad]",text); //found[0] would return hello //found[1] would return bye Below is what I've wrote, but it doesn't seem to be working. I believe the problem is the !==, anybody else have a clue? function mySubStr(strP,startP,endP){ if(endP==0) endP=strP.length-startP; return strP.substr(startP,endP); } function myIndexOf(strP,searchP){ return strP.indexOf(searchP); } function findText(openPin,endPin,hayStack){ var textFound = new Array(); openPin = openPin.toLowerCase(); endPin = endPin.toLowerCase(); var opLength = opLength.length; var epLength = epLength.length; var hsCheck = hsCheck.toLowerCase(); do{ opPos=myIndexOf(hsCheck,openPin); if(opPos!==false){ epPos=myIndexOf(mySubStr(hsCheck,opPos+opLength,0),endP); if(epPos!==false){ textFound[] = mySubStr(hayStack,opPos+opLength,epPos); hayStack = mySubStr(hayStack,opPos+opLength+epPos+epLength,0); hsCheck = hayStack.toLowerCase(); } } }while((opPos!==false) && (epPos!==false)); return textFound; } Link to comment https://forums.phpfreaks.com/topic/119881--/ Share on other sites More sharing options...
lemmin Posted August 15, 2008 Share Posted August 15, 2008 if(opPos!=false){ would evaluate to false if opPos = 0 or false (or anything that evaluates to false), but if(opPos!==false){ would evaluate to true if opPos = 0 (or any value other than false) Did you try the script without the extra '='? Link to comment https://forums.phpfreaks.com/topic/119881--/#findComment-617572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.