irato: preg_replace und das Ersetzen einen Punktes

Hallo zusammen,

ich möchte einen Datei-Extender aus einem String entfernen:

$title="Cats & Dogs.TS";
$ext = ".TS";
$title = preg_replace($ext, "", $title);

Ergebnis:
$title = "C & Dogs"

Der Extender ist dann zwar weg, aber ich find' einfach net die Maskierung um dem dammischen "." das Platzhalterdasein zu entreißen!

Solong!

  1. Hi,

    ich möchte einen Datei-Extender aus einem String entfernen:

    $title="Cats & Dogs.TS";
    $ext = ".TS";
    $title = preg_replace($ext, "", $title);

    Ergebnis:
    $title = "C & Dogs"

    Dazu in diesem Fall reguläre Ausdrücke zu nehmen, ist unsinnig.
    Nutze str_replace.

    Der Extender ist dann zwar weg, aber ich find' einfach net die Maskierung um dem dammischen "." das Platzhalterdasein zu entreißen!

    http://www.php.net/manual/de/regexp.reference.backslash.php

    MfG ChrisB

    --
    The most exciting phrase to hear in science, the one that heralds new discoveries, is not “Eureka!” but “That's funny...” [Isaac Asimov]
  2. Hi,

    $title="Cats & Dogs.TS";
    $ext = ".TS";
    $title = preg_replace($ext, "", $title);

    Ergebnis:
    $title = "C & Dogs"

    Das ist ausserdem glatt gelogen - das „Ergebnis“ des gezeigten Codes ist

    Warning:  preg_replace() [function.preg-replace]: No ending delimiter '.' found

    MfG ChrisB

    --
    The most exciting phrase to hear in science, the one that heralds new discoveries, is not “Eureka!” but “That's funny...” [Isaac Asimov]
  3. Hallo zusammen,

    so habe ich einen Datei-Extender aus einem String entfernt:

    $title="Cats & Dogs.TS";
    $ext = ".TS";

    das wars net:
    $title = preg_replace($ext, "", $title);

    so gehts:
    $title = preg_replace('/.ts/', "", $title);

    Ergebnis:
    $title = "Cats & Dogs"

    Solong!

    1. Hi,

      so gehts:
      $title = preg_replace('/.ts/', "", $title);

      Unsinn bleibt's.

      MfG ChrisB

      --
      The most exciting phrase to hear in science, the one that heralds new discoveries, is not “Eureka!” but “That's funny...” [Isaac Asimov]
      1. Hi Chris,

        hast recht, das sollte dann wohl die beste Lösung sein:

        $ext = ".ts";
        $title = str_replace($ext, "", $title);

        Solong!

        1. Hi!

          hast recht, das sollte dann wohl die beste Lösung sein:
          $ext = ".ts";
          $title = str_replace($ext, "", $title);

          Wenn man davon ausgeht, dass die Zeichenfolge nicht auch noch mal mitten im Dateinamen vorkommt.

          Lo!