glennn.php Posted May 5, 2012 Share Posted May 5, 2012 ok, this is clearly 1st grade code for some, but i'm not there yet - I'm querying posts in WordPress, and the post_content will always have an image in the beginning of the post followed by the content. i don't want to get the image, just the content that's after the image, which is wrapped in anchor tags, of course. <a href="http://path/to/image.jpg"><img src="http://path/to/image.jpg" /></a> <p>Post content yadda, yadda, hoowie</p> obviously a character count won't work, so i need to get anything that follows the first "</a>", say...? is this the best way, or is there an easier way? thanks for anyone's help. GN Quote Link to comment https://forums.phpfreaks.com/topic/262125-query-to-return-value-after-a-certain-character-in-a-field/ Share on other sites More sharing options...
awjudd Posted May 5, 2012 Share Posted May 5, 2012 Strip the tags using php.net/strip_tags and then do a length check? ~awjudd Quote Link to comment https://forums.phpfreaks.com/topic/262125-query-to-return-value-after-a-certain-character-in-a-field/#findComment-1343337 Share on other sites More sharing options...
glennn.php Posted May 5, 2012 Author Share Posted May 5, 2012 no, cause even these image names are going to be different. i'm ok keeping the tags, i just want to use the </a> as a delimiter and store everything up to and including that in one var and everything after that in another var. sorry i wasn't as clear the first time. im realizing that this is probably a php question, perhaps using substr()..? my apologies for this being in mysql... Quote Link to comment https://forums.phpfreaks.com/topic/262125-query-to-return-value-after-a-certain-character-in-a-field/#findComment-1343341 Share on other sites More sharing options...
Pikachu2000 Posted May 6, 2012 Share Posted May 6, 2012 Well, it can be done in a MySQL query if you'd like (as long as you're sure the delimiter will always be '</a>'). SELECT CONCAT( SUBSTRING_INDEX( `field` , '</a>', 1 ) , '</a>' ) AS first_half, SUBSTRING_INDEX( `field` , '</a>', -1 ) AS second_half FROM table WHERE whatever_field = some_value Quote Link to comment https://forums.phpfreaks.com/topic/262125-query-to-return-value-after-a-certain-character-in-a-field/#findComment-1343405 Share on other sites More sharing options...
glennn.php Posted May 6, 2012 Author Share Posted May 6, 2012 yes, that works as well. little easier splitting it with php after i get the results, i've discovered, but this worked out fine. thanks much Quote Link to comment https://forums.phpfreaks.com/topic/262125-query-to-return-value-after-a-certain-character-in-a-field/#findComment-1343407 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.