Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > de.comp.lang.php > #4960
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Newsgroups | de.comp.lang.php |
| Subject | Re: Ist hier noch jemand? str_replace multiple replacement |
| Date | 2024-11-08 17:29 +0100 |
| Message-ID | <lp6sinFpfr7U1@mid.individual.net> (permalink) |
| References | <vgavv1$5s7v$1@solani.org> <lp48b3FdaejU1@mid.individual.net> <vgkov9$l2e0$1@solani.org> |
Detlef Paschke, 2024-11-08 11:25: > Am 07.11.2024 um 17:31 schrieb Arno Welzel: >> Detlef Paschke, 2024-11-04 18:23: >> >> >> [...] >>> So funktioniert es zwar, aber schön ist das auch nicht. >>> >>> str_replace(['./', '../', '\\'], ['','','/'], $datei) >> >> Was ist daran "nicht schön?". > > Schöner fände ich das Ersetzungs-Array so, ['','/'] wie es bei > preg_replace in allen Varianten geht. In einer Variante eben auch mit Nein, preg_replace() arbeitet auch nicht so. Zitat aus <https://www.php.net/manual/en/function.preg-replace.php>: If there are fewer elements in the replacement array than in the pattern array, any extra patterns will be replaced by an empty string. (Zitat Ende) Das wäre dann für ['', '/'] als replacement: './' --> ''; '../' --> '/'; '\\' --> ''; Denn ab dem 3. Suchmuster wird nur '' als Ersetzung verwendet. > logischen ODER Operator, ['/(\.\/|\.\.\/)/', '/(\\\\)/'] und ich hoffte, > dass sich das auf str_replace übertragen lässt. Dem ist aber wohl nicht so. Nein, genau deswegen gibt es ja preg_replace(), weil das "oder" halt ein Teil des regulären Ausdrucks wäre. -- Arno Welzel https://arnowelzel.de
Back to de.comp.lang.php | Previous | Next — Previous in thread | Find similar
Ist hier noch jemand? str_replace multiple replacement Detlef Paschke <schabau@t-online.de> - 2024-11-04 18:23 +0100
Re: Ist hier noch jemand? str_replace multiple replacement Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2024-11-04 22:56 +0000
Re: Ist hier noch jemand? str_replace multiple replacement Detlef Paschke <schabau@t-online.de> - 2024-11-05 10:03 +0100
Re: Ist hier noch jemand? str_replace multiple replacement Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2024-11-05 09:59 +0000
Re: Ist hier noch jemand? str_replace multiple replacement Detlef Paschke <schabau@t-online.de> - 2024-11-05 12:38 +0100
Re: Ist hier noch jemand? str_replace multiple replacement Detlef Paschke <schabau@t-online.de> - 2024-11-05 12:55 +0100
Re: Ist hier noch jemand? str_replace multiple replacement Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2024-11-05 12:19 +0000
Re: Ist hier noch jemand? str_replace multiple replacement Detlef Paschke <schabau@t-online.de> - 2024-11-05 15:27 +0100
Re: Ist hier noch jemand? str_replace multiple replacement Arno Welzel <usenet@arnowelzel.de> - 2024-11-07 17:31 +0100
Re: Ist hier noch jemand? str_replace multiple replacement Detlef Paschke <schabau@t-online.de> - 2024-11-08 11:25 +0100
Re: Ist hier noch jemand? str_replace multiple replacement Arno Welzel <usenet@arnowelzel.de> - 2024-11-08 17:29 +0100
csiph-web