Jump to content

query to return value after a certain character in a field


glennn.php

Recommended Posts

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

 

 

 

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...

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.