aQ Posted July 3, 2007 Share Posted July 3, 2007 Hello! I have a variable ( $theProgram[name], found in a database, contains "MyProgram" ), and I have another one ($program[name], also found in a database, contains "CATEGORY: MyProgram"). I want to search for $theProgram[name] inside $program[name], and if I find it, I want to print out $program[information]. I don't know if this is possible, but help me if you can. Link to comment https://forums.phpfreaks.com/topic/58279-search-for-something-in-a-variable/ Share on other sites More sharing options...
per1os Posted July 3, 2007 Share Posted July 3, 2007 <?php if (eregi($theProgram['name'], $program['name'])) { echo 'String was present.'; }else { echo 'The string was not present'; } ?> Link to comment https://forums.phpfreaks.com/topic/58279-search-for-something-in-a-variable/#findComment-288962 Share on other sites More sharing options...
GingerRobot Posted July 3, 2007 Share Posted July 3, 2007 Dont mean to be picky, but you should use the strstr() function for this as its faster. Link to comment https://forums.phpfreaks.com/topic/58279-search-for-something-in-a-variable/#findComment-288966 Share on other sites More sharing options...
per1os Posted July 3, 2007 Share Posted July 3, 2007 Dont mean to be picky, but you should use the strstr() function for this as its faster. You can, but the speed difference is very minute for 1 record. That and with strstr() you need to make sure you use the === false parameter. Either way works, I just hate using the === operator to check false variables, they bug me. Link to comment https://forums.phpfreaks.com/topic/58279-search-for-something-in-a-variable/#findComment-288978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.