TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-30-2010, 08:36 PM   #1 (permalink)
The Visitor
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
arsitek is on a distinguished road
Default How to take only the path?

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
arsitek is offline  
Reply With Quote
Old 10-30-2010, 10:55 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by arsitek View Post
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.
__________________

Village Idiot is offline  
Reply With Quote
Old 10-31-2010, 05:00 AM   #3 (permalink)
The Visitor
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
arsitek is on a distinguished road
Default

Thanks you very much Village Idiot :)
arsitek is offline  
Reply With Quote
Old 11-03-2010, 09:25 PM   #4 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

A regular expression would work as well.

#<img.+src=(?:"|')(.*?)(?:"|').+/>#i

I haven't fully tested but that should match only in image tags and " or ' could be used.
__________________
Eric
wGEric is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get full path dhaval General 4 12-23-2009 04:28 AM
Next class project? allworknoplay The Lounge 6 04-18-2009 08:33 PM
Nginx Rewrite Causing Wrong Path for PHP Script stewart General 0 11-09-2008 12:32 AM
ZF Custom Helpers Path freenity Advanced PHP Programming 0 04-27-2008 05:39 PM
Accessing Variables from Conf file to Upload Class Gareth Absolute Beginners 10 02-22-2008 01:27 AM


All times are GMT. The time now is 10:09 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design