将html图像标记存储在数据库中

I am trying to create a content management system that allows the user to generate html which is then stored in a database.

Everything works as expected except images. When I inspect the image elements with the dev tools the url appears correct. However, if I click the url the browser prefixes the image url with the url of the current page.

So for example:

Current Page: testProject.com/code/pages/index.php

Image url : http://testProject.com/code/pages/images/image_1.jpg

If i click the url in chrome dev tools I end up with the following url in the address bar:

testProject.com/code/page//"http:/testProject.com/code/pages/images/images_1.jpg/"

I'm relatively new to programming so any help would be much appreciated.

Thanks.

Make sure your src path is correct.

It should be:

<img src="http://project.com/path/to/image.jpg" />

no extra quotes, two slashes in http://

or

<img src="/path/to/image.jpg" />

  • the first "/" making it an "absolute path"

You need to apply str_replace() to remove the extra characters:

 str_replace("testProject.com/code/page//", "", "$your_link");