Browse Source

php preg_replace() fragment

I'd forgotten the specifics here.
Brennen Bearnes 2 months ago
parent
commit
5c13753995
1 changed files with 16 additions and 0 deletions
  1. 16
    0
      fragments/php-preg-replace.php

+ 16
- 0
fragments/php-preg-replace.php View File

@@ -0,0 +1,16 @@
1
+<?php
2
+$url = 'https://www.mouser.com/images/keystoneelectronics/images/Battery_1047_SPL.jpg';
3
+print $url . "\n";
4
+
5
+print preg_replace('
6
+  {
7
+    ^              # start of line
8
+      (.*images/)  # domain etc.
9
+      (.*)/images/ # middle bit
10
+      (.*)         # image filename
11
+    $              # EOL
12
+
13
+  }x',
14
+  '$1$2/lrg/$3',
15
+  $url
16
+);