/    Sign up×
Community /Pin to ProfileBookmark

Help with pattern (preg_match_all)

Hi

I’m working on a class to get mails and saves it i an archive.
To grab the inlined images of the message i use ‘preg_match_all’ to grab the path to the images, which will be changed later.
It works perfect in this example:

[code=php]
$message = ‘<img width=”220″ height=”43″ id=”_x0000_i1028″ src=”cid:[email protected]″ alt=”Data Gården logo”>’;

$SearchImageName = ‘image001.jpg’;

preg_match_all(‘/src=”cid:(‘.$SearchImageName.’)(.*)”/U’, $message, $inline_match_array[]);
[/code]

In this example the above search pattern does not work because it only has a wildcard behind the $SearchImageName. But I can’t make it work with a wildcard in front of the $SearchImageName.
I also have a problem with the file extension has been changed to .ashx instead of .jpg :

[code=php]
$message = ‘<img id=”content_0_img” src=”http://danskeark.dk/~/media/Dark/Nyheder/Fokus-fotos/2012_10_17_fokus%20kopi.ashx?mw=470&amp;as=1″>’

$SearchImageName = ‘2012_10_17_fokus kopi.jpg’;
[/code]

Any ideas for a search pattern?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 20.2012 — It might be "nicer" to find a way to do this with the [url=http://php.net/dom]DOM extension[/url], but this ugly bunch of code seems to work and cover most possibilities:
[code=php]
<?php

$message = '<img id="content_0_img" src="http://danskeark.dk/~/media/Dark/Nyheder/Fokus-fotos/2012_10_17_fokus%20kopi.ashx?mw=470&amp;as=1">';

$SearchImageName = '2012_10_17_fokus kopi.';

$findMe = '('.preg_quote($SearchImageName).'|'.
preg_quote(urlencode($SearchImageName)).'|'.
preg_quote(rawurlencode($SearchImageName)).')';
$regexp = '/src=["']([^"']*'.$findMe.')([^"']*)["']/i';
//echo "<pre>".htmlspecialchars($regexp)."</pre>n";

preg_match_all($regexp, $message, $inline_match_array);

echo "<pre>".print_r($inline_match_array, 1)."</pre>";
[/code]
Copy linkTweet thisAlerts:
@dbkauthorOct 20.2012 — Thanks NogDog

Looking forward to test the code!

I never really looked into the DOM thing you mention, but maybe it's about time.

Thanks again!
×

Success!

Help @dbk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...