Jump to content

Recommended Posts

hey everyone,

 

i'm more of a str_replace replace guy so the thought of the following made my head hurt. :lol:

 

this is where i'm at so far:

$url = geturl();
$lightboxer = 'Lightbox_' . $this->containerid;

$find = "<a href=\"$url/attachment.php?attachmentid=xxxx\">Attachment xxxx</a>";

$replace = "<a href=\"$url/attachment.php?attachmentid=xxxx\" id=\"attachmentxxx\" rel=\"$lightboxer\"><img title=\"Click image for larger version\" class=\"thumbnail\" style=\"\" border=\"0\"></a>";

 

it seems pretty simple but the xxxx can be any random number found in $find.  that's where i'm kinda lost so i'm here asking for a lil help from the pro's! :D

 

 

Link to comment
https://forums.phpfreaks.com/topic/192435-uhg-this-one-makes-my-head-hurt/
Share on other sites

try this one

$find = '/<a href="(.+)\/attachment\\.php\\?attachmentid=(\\d+)">Attachment \\2\\<\/a>/i';
$replace = '<a href="\\1/attachment.php?attachmentid=\\2" id="attachment\\2" rel="'.$lightboxer.'"><img title="Click image for larger version" class="thumbnail" style="" border="0"></a>';

$result = preg_replace($find, $replace, $str);

 

In case it's not working post error and post how exactly looks data that u are trying to match:

is it text file with bunch of url's line by line or what?

Sader, by using \\ you are essentially double escaping characters, meaning you expect the pattern to contain a literal backslash followed by a literal version of the backslash escaped character you wished to use. So for example \\d+ will match backslash followed by any number of d's. The only time you want to escape Regex backslash character sequences is when you use double quote delimiters for the PHP string (in this case $find).

 

Aside from that at a glance it looks ok.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.