Jump to content

Recommended Posts

Hi,

 

I have problem getting the value in this string. The regex im using is : 

 

preg_match_all('#<span class=\"header\">(.*)</span>#', $file_string, $titles);

 

and it returns fine when i search 

<span class="header">A Radiological Assessment of Scottish Edible Seaweed Consumption</span>

but when i search :

<span class="header">A Radiological Assessment of Scottish Edible Seaweed
Consumption</span>

it returns Null....As far as I can see, its the new line in the middle of the string cause the regrex to just pass it.

 

Any help please ? Thank you.

Link to comment
https://forums.phpfreaks.com/topic/281664-catching-value-which-contain-new-line/
Share on other sites

dot-all . doesn't normally match newlines. Use the /s flag to make it do so.

Also use an ungreedy .*? inside your expression or else it might not match the way you want it to.

preg_match_all('#(.*?)#s', $file_string, $titles);

Hi, Thank your for the suggestion. Now it does return the value i previously failed to get. However, now this value is failed to return :

<span class="header">The provision of European information by public libraries in the UK</span>

Im confuse :(

Heres the code

$file_string = file_get_contents('http://www.emeraldinsight.com/search.htm?st1='.$searchterm.'&ec=1&bf=1&ct=jnl&nolog=503574&displayno=30&page='.$currentpagenumber.'');
preg_match_all('#<span class=\"header\">(.*?)</span>#s', $file_string, $titles);

if( count($titles[1]) > 0)
{
   for($i = 0; $i < count($titles[1]); $i++) {
     echo "my count".$i." contains : ".$titles[1][$i]."<br>";
   }
}
Edited by kangkingkong

well in any case, these are the values I used, based on the context of your posts:

 

 

$searchterm="provision+of+European";
$currentpagenumber='1';
 
$file_string = file_get_contents('http://www.emeraldinsight.com/search.htm?st1='.$searchterm.'&ec=1&bf=1&ct=jnl&nolog=503574&displayno=30&page='.$currentpagenumber.'');
preg_match_all('#<span class=\"header\">(.*?)</span>#s', $file_string, $titles);
 
if( count($titles[1]) > 0)
{
   for($i = 0; $i < count($titles[1]); $i++) {
     echo "my count".$i." contains : ".$titles[1][$i]."<br>";
   }
}
and here are the results:

 

my count0 contains : European information: the pattern of provision in Scotland
my count1 contains : The provision of European information by public libraries in the UK
my count2 contains : The provision of European information to the academic community in university libraries: a case study of a European Documentation Centre
my count3 contains : Problems, needs and service provision related to stimulant use in European prisons
my count4 contains : Can Pension Systems Cope? Population Ageing and Retirement Income Provision in the European Union
my count5 contains : The European information needs of secondary school teachers in Scotland: recent developments in the provision of information to schools and colleges
my count6 contains : The pattern of provision of European Union information in France and the United Kingdom: a comparative study of services
my count7 contains : Methodological problems of sampling young homeless people in four European societies with different levels of service provision and definitions of homelessness
my count8 contains : Electronic public information and Europe: an electronic forum in support of transparency and openness in government
my count9 contains : Real estate education in Europe: some perspectives on a decade of rapid change
my count10 contains : Strategic development related to the Europeanization of UK logistics and distribution service suppliers
my count11 contains : User involvement in the illegal drugs field: what can Britain learn from European experiences?
my count12 contains : Multi-racial Provision: An Integral Part of Library and Information Services
my count13 contains : European vocational education and training: a prerequisite for mobility?
my count14 contains : Commonplaces
my count15 contains : Central and Eastern European business information: a review
my count16 contains : Central and Eastern European business information: a review
my count17 contains : New Challenges in Training
my count18 contains : Training for Europe – Should Britain Follow the German Model?
my count19 contains : Reluctant enablers: Competition in local government in Ireland and the UK
my count20 contains : Trade unions and the training of health and safety representatives: Challenges of the 1990s
my count21 contains : European Union Enterprise Policy and the Hospitality Industry
my count22 contains : The implementation of the European Credit Transfer system as a curriculum evaluation tool
my count23 contains : HRD in Europe
my count24 contains : The provision of psychotherapy: an international comparison
my count25 contains : Aslib open meeting: Euronet and you
my count26 contains : Forwarders and Computers: More Evidence for Regulation?
my count27 contains : Continuing vocational training in Europe
my count28 contains : Food and residential care in old age
my count29 contains : The Role of the European Community in Civil and Environmental Emergencies
so my guess is either your $searchterm and $currentpagenumber don't have expected values, or your problem is elsewhere.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.