Skip to main content
Inspiring
December 12, 2012
Question

Echo images in certain parts of description field

  • December 12, 2012
  • 1 reply
  • 1539 views

For every post in this section I have about 7-10 related images. I fill out a description using a wysiwig editor to insert into the database. Each post usually has about 5 paragraphs about the article, followed by <h2> with paragraphs about technical specs. What I want to do is be able to echo the images specifically.

1- Image before the first paragraph

3- After the third paragraph

1- After the <h2>

2-5 next to the paragraphs of the technical specs.

My question is one, can I acheive this, and two where should I start reading about how to acheive this. I beleive I will use regex but have read upon other methods and know this will be a mix of php/css. But don't know too much from there, as this is more complicated than what I do know.

If anyone can link me to some articles/tutorials or books that explain in great detail I would appreciate it!

Thanks!

This topic has been closed for replies.

1 reply

Participating Frequently
December 14, 2012

Are you using <p> tags for your paragraphs? If so, you can probably just use a few php string functions to insert your image tags.

Inspiring
December 14, 2012

Yes, so im using the CKEditor,  I start a new paragraph by pressing enter which formats the <p> tags. I can change a heading say after the story to whatever heading I want ex. <h2> and after that heading I have areas of technical specs. Similar to below. That is what is inserted to the db, but of course I just echo the 'description' which displays it. So I want to be able to count <p> and <h2> tags and be able to insert the images specifically.

<p>Text paragraph 1 </p>

<p>Text paragraph 2</p>

<p>Text paragraph 3</p>

<p>Text paragraph 4</p>

<p>Text paragraph 5</p>

<h2>New heading</h2>

<h3>Another heading</h3>

<p>Text paragraph</p>

<h3>Another heading</h3>

<p>Text paragraph</p>

<h3>Another heading</h3>

<p>Text paragraph</p>

<h3>Another heading</h3>

<p>Text paragraph</p>

Thanks

Participating Frequently
December 14, 2012

I'm not a php developer, so I don't know the most efficient method - but I would probably use strpos()to locate all of the occurances of the tags of interest. Or use something like this:

http://www.phpro.org/examples/Find-Position-Of-Nth-Occurrence-Of-String.html

Then use substr_replace() to insert your image tags.