Jump to content

Problemas numa string


Llaverola
 Share

Recommended Posts

function parte_anterior($src)
{
  $minus = strpos($src, '-');
  if ($minus > 0) {
    return trim(substr($src, 0, $minus));
  }
  return $src;
}

/* ... */

/* exemplo de uso */
$tipo = parte_anterior($BDstring);

Não testado.

Verifica principalmente casos anormais de string vinda da BD

"-"; "- qualquer coisa"; "                - qualquer coisa"; "qualquer coisa"

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.