jeff5656 Posted October 20, 2011 Share Posted October 20, 2011 Let's say I have a variable called $big_paragraph I want to display the variable IF it contains the word "hello". The word may or may not be there AND it could be anywhere in that paragraph (separated by a space before and after it to signify that it is a word). So I can't use substr since it assumes I know the position. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/249453-display-part-of-a-string/ Share on other sites More sharing options...
AyKay47 Posted October 20, 2011 Share Posted October 20, 2011 strpos Quote Link to comment https://forums.phpfreaks.com/topic/249453-display-part-of-a-string/#findComment-1280791 Share on other sites More sharing options...
jeff5656 Posted October 20, 2011 Author Share Posted October 20, 2011 Actually I just realized it's a little more complicated than that. I want to query the database and only retrieve those records that contain hello in the field "big_paragraph". I have $query = select * from table_list where (big_paragraph = 'hello' OR small_paragraph = 'hello' or variable55 = 'hello')"; Can I use strpos inside a query? If so what would the syntax be? I'm always bad with figuring out where to put the quotation marks. :-) Quote Link to comment https://forums.phpfreaks.com/topic/249453-display-part-of-a-string/#findComment-1280793 Share on other sites More sharing options...
jeff5656 Posted October 20, 2011 Author Share Posted October 20, 2011 Never mind I figured it out: where (big_paragraph like '%hello%' Quote Link to comment https://forums.phpfreaks.com/topic/249453-display-part-of-a-string/#findComment-1280795 Share on other sites More sharing options...
AyKay47 Posted October 20, 2011 Share Posted October 20, 2011 you might be able to use the LIKE clause here.. $query = mysql_query("SELECT * FROM tbl WHERE field LIKE '%hello%'"); Quote Link to comment https://forums.phpfreaks.com/topic/249453-display-part-of-a-string/#findComment-1280796 Share on other sites More sharing options...
jeff5656 Posted October 20, 2011 Author Share Posted October 20, 2011 Looks like we posted at the same time. Yep, LIKE did the trick. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/249453-display-part-of-a-string/#findComment-1280866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.