for single vs double quotes, simply replace all single quotes with double first, or vice versa.
Code: Select all
$string = str_replace('"',"'",$string);
you goofed your code though, as you simply replace $string each time.
either:
Code: Select all
$result = preg_match_all("/<img(.*?)>/", $string, $matches);
if ($result) {
for($i=0; $i<count($matches); $i++) {
$string = preg_replace("\"" . $matches[0][$i] . "\"", "<img alt='Mailer' src='cid:attach-$i'>", $string);
echo $string;
}
}
or:
Code: Select all
$result = preg_match_all("/<img(.*?)>/", $string, $matches);
if ($result) {
for($i=0; $i<count($matches); $i++) {
$string[$i] = preg_replace("\"" . $matches[0][$i] . "\"", "<img alt='Mailer' src='cid:attach-$i'>", $string);
}
}
foreach ($string as $one) {
echo $one;
}
now then, let's see...
First, you'll want the single to double, then you'll want the src info... If you knew they weren't going to use an alt param, you could simply do this:
Code: Select all
$result = preg_match_all("/<img src=['\"](\S+?)['\"][ ]?[\/]?>/i", $string, $matches);
// I added the "[ ]?[\/]?" in for the xhtml img tags. (hope I got that right.)
// in other words, "src=''>", "src='' />", "src='' >", or "src=''/>"
// The brackets are just for readability
// Since we're doing the src here, the ['\"] checks for either ' or "
// the \S is for non-whitespace characters
// the + means there has to be at least one character there
// the i at the end makes it case insensitive
if ($result) {
for($i=0; $i<count($matches); $i++) {
$string = "<img alt='Mailer' src='cid:attach-{$i}'>";
echo $string;
}
}
Ok.. I really don't know why you have a preg_replace in the for loop. Besides that, you've got it wrong. perl REs need to be enclosed in / or #. In other words, a valid version of your pRE would be:
Code: Select all
$string = preg_replace("/\"{$matches[0][$i]}\"/i", "text", $string);
But all that RE does it replace the one text with the second. And the second contains nothing of the first. Therefore, it does nothing. ^^;