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 08-03-2009, 12:00 PM   #1 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default str_replace - img

Hi i need away to strip away the img html and get just the src part of the html image.

Then I need to take the URL to the image and give it a class like

$image=[URL to Image]

then what i want it to do is any other html code like <div> or tables or any HTML code to delete, But all images must be able to get an image class like the one above.

Can any one help me
russellharrower is offline  
Reply With Quote
Old 08-03-2009, 12:48 PM   #2 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

server side or client side?
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 08-03-2009, 12:53 PM   #3 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

server side, i believe.

basically i want to take this rss feed http://feedproxy.google.com/OfficialGmailBlog

and then take the images from the post.
russellharrower is offline  
Reply With Quote
Old 08-03-2009, 01:05 PM   #4 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

You could do it with a regex, only the images will have a src.
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 08-03-2009, 01:07 PM   #5 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

The php function would be preg_match.

Match src="................"
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 08-03-2009, 02:06 PM   #6 (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

Thats not true, off the top of my head I know it appears in the script and iframe tags.
__________________

Village Idiot is offline  
Reply With Quote
Old 08-03-2009, 04:58 PM   #7 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
Thats not true, off the top of my head I know it appears in the script and iframe tags.
Yes you are right, sorry I meant within that link. But I am still wrong, it appears in the javascript includes. However, this can all still be filtered out with the regex.
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 08-03-2009, 05:13 PM   #8 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

Can someone give an example?
russellharrower is offline  
Reply With Quote
Old 08-04-2009, 06:47 AM   #9 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

I have not tested the below, so it probably wont work, but it will give you a rough idea. Best thing to do is to find an online regex maker - it will allow you to paste some code in and then write your regex and it will match live as you type. ie. http://gskinner.com/RegExr/

PHP Code:
$pattern '@[a-zA-Z0-9_.-]*<img[a-zA-Z0-9_.-]*src="http://www.[a-zA-Z0-9_.-]*"[a-zA-Z0-9_.-]*/>@i';
$subject '<div id="images"><img src="http://www.jaoudestudios.com/images/image1.jpg" alt="This is an image" /></div>';
preg_match($pattern$subject$matches); 
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!

Last edited by codefreek : 08-04-2009 at 12:53 PM. Reason: PHP tags added - please read http://www.talkphp.com/lounge/4563-prettifying-pasted-code-talkphp.html
JaoudeStudios is offline  
Reply With Quote
Old 08-04-2009, 10:55 AM   #10 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

To get the img src you could use something like this, now baring in mind i'm not the best at regex, so i'm sure Salathe will post with improvements!
PHP Code:
<?php
$pattern 
'~<img(?:.*)src="(.+?)"(?:.*)\/>~i';
$subject '<div id="images"><img alt="awd" src="http://www.jaoudestudios.com/images/image1.jpg" alt="This is an image" /></div>';
preg_match($pattern$subject$matches);

echo 
$matches[1];
Now, to match all img src, you need to do thus:
PHP Code:
<?php
$pattern 
'~<img(?:.*)src="(.+?)"(?:.*)\/>~i';
$subject '<div id="images"><img alt="awd" src="http://www.jaoudestudios.com/images/image1.jpg" alt="This is an image" /><img alt="awd" src="http://www.jaoudestudios.com/images/image1.jpg" alt="This is an image" /><img alt="awd" src="http://www.jaoudestudios.com/images/image1.jpg" alt="This is an image" /><img alt="awd" src="http://www.jaoudestudios.com/images/imagawdawd1.jpg" alt="This is an image" /><img alt="awd" src="http://www.jaoudestudios.com/images/iawdawd1.jpg" alt="This is an image" /></div>';
preg_match_all($pattern$subject$matches);

foreach(
$matches[1] as $match)
{
     echo 
'<br />' $match;
}
Alternitivly, you could use xpath + domdocument:

PHP Code:
$subject '<div id="images"><img alt="awd" src="http://www.jaoudestudios.com/images/image1.jpg" alt="This is an image" /><img alt="awd" src="http://www.jaoudestudios.com/images/image1.jpg" alt="This is an image" /><img alt="awd" src="http://www.jaoudestudios.com/images/image1.jpg" alt="This is an image" /><img alt="awd" src="http://www.jaoudestudios.com/images/imagawdawd1.jpg" alt="This is an image" /><img alt="awd" src="http://www.jaoudestudios.com/images/iawdawd1.jpg" alt="This is an image" /></div>';
$pDom = new DOMDocument();
libxml_use_internal_errors(true);
$pDom->loadHTML($subject);
libxml_use_internal_errors(false);

$pXPath = new DOMXPath($pDom);
$pImgs$pXPath->evaluate("//img");


foreach(
$pImgs as $pImg)
{
    echo 
'<br />' $pImg->getAttribute('src');

__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 08-04-2009, 11:40 AM   #11 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

New CODE:

I have come up with a way to post the information
Code:
foreach($pImgs as $pImg)
{
 $imageq = $pImg->getAttribute('src');
 
 $Curl_Session = curl_init('http://www.example.com/cache7/image.php');
 curl_setopt ($Curl_Session, CURLOPT_POST, 1);
 curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "imageq=$imageq");
 curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
 curl_exec ($Curl_Session);
 curl_close ($Curl_Session);
}
however I am getting this error

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /home/example/public_html/image/index.php on line 49

what is this and how do I fix this?

Thanks

Last edited by russellharrower : 08-04-2009 at 12:56 PM.
russellharrower is offline  
Reply With Quote
Old 08-07-2009, 09:51 PM   #12 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Simply, deactivate the horrible safe_mode or disable the open_basedir configuration as the warning says :)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
The Following User Says Thank You to Kalle For This Useful Post:
russellharrower (08-08-2009)
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


All times are GMT. The time now is 09:06 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