Jump to content
TS91

Preg Match

Recommended Posts

TS91

Boas,

estou a tentar obter uma string de um ficheiro atraves do preg match.

Eu tenho algo do genero:

/**

Category Template: nome

*/

mais texto.

Eu queria verificar se existe em a parte de "Category Template: nome" e returnar para uma string

Alguem tem ideia de que pattern necessito para o preg_match?

Cumprimentos

Share this post


Link to post
Share on other sites
Rui Carlos

Algo deste género deve funcionar:

$matches = null;
$flag = preg_match('/\\/\\*\\*\\s*Category\\sTemplate:\\s*([a-zA-Z0-9\\s_-]*)\\n/', $txt, $matches);
$name = $matches[1];

http://ideone.com/iibUqE

Atenção à parte final da expressão regular, pois não sei que caracteres o nome do template pode conter.

Share this post


Link to post
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

×
×
  • 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.