Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get a part of string

Status
Not open for further replies.

KeziaKristina

Programmer
Nov 1, 2002
13
ID
How can I get a part of string which contain newline (\n)?

Ex:
$string = &quot;<HTML> \n <BODY> \n <?php print &quot;Something 2 print&quot;;\n print $a; \n ?> </BODY> \n </HTML>\n&quot;;

I want to get string between <?php .... ?>. And how can i get them?

I have try it with many way, including with regular expression, but it doesn't work. Does regular expression support multiline?
 
You need to protect special characters like ?, e.g.
my $str='<?php .... ?>';
if($str=~/\?(.*)\?/){print &quot;found $1\n&quot;;}

hjope this helps, svar
 
You need the '/s' modifier to make the '.' match the newline character.
[tt]
$string =~ /\?(.*)\?/s;
[/tt]
jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top