Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question Get the array values into img tags?

    Code:
    <?php
    $str = '<img border="0" hspace="2" vspace="2" align="left" width="120" height="120" alt="image" src="path/to/image/image.jpg" />
    Some text, another image:<img width="120" height="120" alt="" src="path/to/image/image.jpg" />
    and a third<img src="path/to/image/image.jpg" alt="" />';
    preg_match_all('~<img ([^>]+)>~i', $str, $matches);
    $images = array();
    foreach ($matches[1] as $str) {
    preg_match_all('~([a-z]([a-z0-9]*)?)=("|\')(.*?)("|\')~is', $str, $pairs);
    $images[] = array_combine($pairs[1], $pairs[4]);
    }
    echo '<pre>' . print_r($images, true) . '</pre>';
    ?>
    Some output...
    Code:
    [border] => 0
    [hspace] => 2
    [vspace] => 2
    [align] => left
    [width] => 120
    [height] => 120
    [alt] => image
    [src] => path/to/image/image.jpg
    How do I get the array values into this:
    <img border="$arr0" hspace="$arr1" vspace="$arr2" align="$arr3" width="$arr4" height="$arr5" alt="$arr6" src="$arr7" />
    (based on the fact the image could be in any of these formats)...
    <img name="newsletter/FCKeditor/uploadfiles/image/8ball.jpg" src="" width="64" height="64" alt="8ball">
    <img alt="" width="64" height="64" src="newsletter/FCKeditor/uploadfiles/image/8ball.jpg" />
    <img border="0" hspace="0" align="left" width="64" height="64" alt="8ball" src="newsletter/FCKeditor/uploadfiles/image/8ball.jpg" />
    <img border="0" hspace="2" vspace="2" align="absMiddle" width="64" height="64" alt="" src="newsletter/FCKeditor/uploadfiles/image/8ball.jpg" />
    Code:
    $mail->AddEmbeddedImage('FCKeditor/uploadfiles/image/8ball.jpg', '8ball2', '8ball.jpg');
    $mail->Body = 'Embedded Image: <br>
    <img name="ball" src="cid:8ball" width="64" height="64" alt="8ball">
    <br>
    Embedded Image 2: <img name="8ball2" src="cid:8ball2" width="64" height="64" alt="8ball2">';
    Will the array go according to the array value, ie: width=array['width']
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,294
    Thanks
    4
    Thanked 203 Times in 200 Posts
    Quote Originally Posted by student101 View Post
    Will the array go according to the array value, ie: width=array['width']
    Yes it will. Just use the index with the quotes the way you've shown it for each portion of the array that you need.
    Dave .... HostMonster for all of your hosting needs

  • #3
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Cool, how do I check how many images there are?
    That would depend on the loop WHILE or FOREACH.

    Edit:
    Phrased wrong!
    Variable looks like this;
    PHP Code:
     $match '<p>Some image</p><img name="newsletter/FCKeditor/uploadfiles/image/8ball.jpg" src="" width="32" height="32" alt="8ball">
    <p>Another image</p><img alt="" width="151" height="121" src="newsletter/FCKeditor/uploadfiles/image/8ball.jpg" />
    <p>Some image</p><img border="0" hspace="0" align="left" width="151" height="121" alt="8ball" src="newsletter/FCKeditor/uploadfiles/image/8ball.jpg" />
    <p>Some image</p><img border="0" hspace="2" vspace="2" align="absMiddle" width="151" height="121" alt="" src="newsletter/FCKeditor/uploadfiles/image/8ball.jpg" />'

    How do I check how many images there are now?
    Last edited by student101; 08-11-2009 at 04:14 PM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,294
    Thanks
    4
    Thanked 203 Times in 200 Posts
    What you posted isn't array so the previous discussion about an array does not apply. All you have there is a single string of information. If, as shown in your first post, that gets turned into an array the array function named count will tell you how many elements are in the array. Whether or not it will work in your situation is unknown. You'd need to post the entire contents of the array or simply try it and see what you get.
    Dave .... HostMonster for all of your hosting needs

  • #5
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Sorry, I've got so many test pages - confusing code!
    Based on the above code I see what you mean...

    Let me post what I've created.
    PHP Code:
    <?php 
    require("class.phpmailer.php"); 
    $mail = new PHPMailer(); 
    $mail->IsSMTP(); // telling the class to use SMTP 
    $mail->Host "mail.example.com"// SMTP server 
    $mail->From "mail@example.com";
    $mail->FromName "Webmaster";
    $mail->AddAddress("undisclosed-recipients:;");
    $mail->AddBCC('mail@example.com');
    $mail->WordWrap 50
    $mail->Subject "PHPMailer Message";
    $mail->IsHTML(true); 
     
    //this part needs to be looped or something...
    $mail->AddEmbeddedImage('FCKeditor/uploadfiles/image/8ball.jpg''8ball''8ball.jpg');
    $mail->AddEmbeddedImage('FCKeditor/uploadfiles/image/8ball.jpg''8ball2''8ball.jpg');
    $mail->Body 'Embedded Image: <br><img name="ball" src="cid:8ball" width="64" height="64" alt="8ball"><br>Embedded Image 2: <br><img name="8ball2" src="cid:8ball2" width="64" height="64" alt="8ball2">';
    //end loop...
     
    if(!$mail->Send()) { 
    echo 
    'Message was not sent.'
    echo 
    'Mailer error: ' $mail->ErrorInfo
    } else { 
    echo 
    'Message has been sent.'

    ?>
    Last edited by student101; 08-11-2009 at 07:06 PM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #6
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by djm0219 View Post
    Whether or not it will work in your situation is unknown. You'd need to post the entire contents of the array or simply try it and see what you get.
    I know that what I would like to do is possible, I just don't know how to do it.
    I need to loop through the images in the variable and assign them accordingly toward the PHPmail structure, with no clue on how to do that.

    Have seen that Graphicmail and Mailchimps haven't developed anything better than my newsletter application and that you need to have a working internet connection in order to see the posted images.

    I am also the type of person who just wont give up on something that I know is possible, hope you know what I mean.

    Venegal helped me out with a regex example but that stopped working.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •