10-30-2010, 10:55 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by arsitek
I using CKFinder to let user browse the files from server to get path location of file direct to input form.
The problem is where the value of input form become like this:
PHP Code:
<p> <img alt="" height="312" src="http://localhost/house/images/images/home-office-3-582x312.jpg" width="582" /></p>
What PHP can do to clean that text input so I get only
PHP Code:
http://localhost/house/images/images/home-office-3-582x312.jpg
to save on database
Thanks for help
|
Lets take what we know about the string to see what we can do. We know:
1. It always will start with http://
2. It always ends with "
So basically what you need to do find the occurrence of every http:// and find the quote directly after it then take the contents between those positions. I haven't tested this, but something like the following should work
PHP Code:
<? $off=0; $start="http://"; $end = "\"";
while(1) { //If a link is found in the text if(stripos($haystack,$start,$off) !== false) { //Set the temporary start and end positions $startPos=stripos($haystack,$start,$off); $endPos=stripos($haystack,$end,$location); //Grab the current link $link=substr($haystack,$startPos,$endPos-$startPos) //Do what you want to the link here such as add it to an array //Set the offset to the end so it can search for the next link $off=$endPos; } else { break; } } ?>
Alternatively, if your code is always going to be well formed XHTML use an XML parser such as simpleXML.
|
|
|
|