Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[PHP] Problem beim matchen/replacen

Empfohlene Antworten

Veröffentlicht

hallo,

ich versuche mittels match und replace bilder die in einem %7Boption%7D-TAG sind zu finden und zu ersetzen.

Beispiel:

$content = 'Das hier ist ein Contenteintrag
[IMG]small_Bildschirmfoto 2012-08-26 um 14.08.20.png[/IMG]
[IMG]small_Bildschirmfoto 2012-08-27 um 21.36.00.png[/IMG]
[IMG]small_Bildschirmfoto 2012-08-27 um 22.12.00.png[/IMG]';[/PHP]

Der Aufruf wäre dann:

[PHP] if(preg_match_all("/\[IMG\](.*)\[\/IMG\]/", $text, $hits) > 0) {
foreach( $hits as $i => $k ) {
$fullmatch = $hits[0][$i];
$filename = $hits[1][$i];
$text = str_replace($fullmatch, $this->media->checkFileExist($filename), $text);
}
}

über media wird geprüft ob das Bild existiert und dann entsprechend als html-tag zurück gegeben.

mein problem ist nun, das ich die ersten 2 bilder umgewandelt bekomme, bild 3 wird nicht umgewandelt.

var_dump sieht ok aus:

    array(2) {
[0]=>
array(3) {
[0]=>
string(58) "[IMG]small_Bildschirmfoto 2012-08-26 um 14.08.20.png[/IMG]"
[1]=>
string(58) "[IMG]small_Bildschirmfoto 2012-08-27 um 21.36.00.png[/IMG]"
[2]=>
string(58) "[IMG]small_Bildschirmfoto 2012-08-27 um 22.12.00.png[/IMG]"
}
[1]=>
array(3) {
[0]=>
string(47) "small_Bildschirmfoto 2012-08-26 um 14.08.20.png"
[1]=>
string(47) "small_Bildschirmfoto 2012-08-27 um 21.36.00.png"
[2]=>
string(47) "small_Bildschirmfoto 2012-08-27 um 22.12.00.png"
}
}[/PHP]

hat jemand eine Idee?

Naja der var_dump zeigt doch schon das Ergebnis - dementsprechend:


$count = count( $hits[0] );
for( $i = 0;$i < $count;$i++ ) {
$fullmatch = $hits[0][$i];
$filename = $hits[1][$i];
}
[/PHP]

Ansonsten 'PREG_SET_ORDER' bei preg_match_all() nutzen - ich glaube dieses Ergebnis wolltest du erreichen; dementsprechend die Schleife:


foreach( $hits as $i => $k ) {
$fullmatch = $hits[$i][0];
$filename = $hits[$i][1];
}
[/PHP]

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.