GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Need regular expression help (https://gfy.com/showthread.php?t=824532)

DigitalPimp 04-26-2008 01:56 PM

Need regular expression help
 
I got the following to match an image tag with a path beginning with a / and replace it with a variable called domain that ends with a /

$a = eregi_replace(" src=\"/"," src=\"$domain/",$a);

I want to know how I can write one or more new lines to match a similar image tag path that does not begin with a / and does not begin with a http for example

<img src="images/someimage.gif">

GrouchyAdmin 04-26-2008 02:42 PM

Why don't you just do this in .htaccess, or set a <base href=.../>? What you're trying to fix shouldn't really be done that way. However, you can src=\"(/?) to just assume another localized request.

If you really want a semi-decent way to grab and rewrite your links:
Code:

$preg = "/[\s]+[^>]*?src[\s]?=[\s\"\']+(.*?)[\"\']+.*?>/i";
  preg_match_all($preg,  $all_of_content_here, $outvar, PREG_PATTERN_ORDER);

Then just walk that to fix all hrefs. You can preg, or ereg if you want. I'll try to make that easy for ya with the following sample
Code:

foreach ($outvar as $imgsrc) {
  if (eregi($domain, $imgsrc)) {
  // is complete
  } elseif (eregi("^/", $imgsrc)) {
  // starts with a /
  } else {
  // assume it's local
  }
  }


DigitalPimp 04-26-2008 03:14 PM

Thanks for the tips, trying now.


All times are GMT -7. The time now is 09:31 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123