Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8768219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:00:57+00:00 2026-06-13T17:00:57+00:00

I want to use regex to recognize space in the .pdf file name So

  • 0

I want to use regex to recognize space in the .pdf file name

So far i have been able to recognize src link to the file but it does not recognize the spaces in file name.

   <?php
   echo "<h1>Reading content from ITM website!</h1>";
   $ch = curl_init("http://domain.edu/index.php?option=com_content&view=article&id=58&Itemid=375&alias=lms");
   $fp = fopen("example_homepage.txt", "w");

   curl_setopt($ch, CURLOPT_FILE, $fp);
   curl_setopt($ch, CURLOPT_HEADER, 0);

   curl_exec($ch);
   curl_close($ch);
   $my_file="example_homepage.txt";
   $handle = fopen($my_file, 'rb');
   $data = fread($handle,filesize($my_file));

   $contents = strstr(file_get_contents('example_homepage.txt'), 'More quick links');
   $new_content = str_replace('<a href="', '<a href="http://www.domain.edu', $contents);
   $regex = '@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.\,]*(\?\S+)?)?)*)@';
   $text = preg_replace($regex, '<a href="$1">$1</a>', $new_content);
   //echo $new_content;
   echo $text;
   fclose($fp);
   ?>

Current Output:

http://www.domain.edu/academiccalendar/Notice for final practical.pdf" target="_blank">Title

In this “Notice for final practical.pdf” does not appear as URL and just appears as text.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:00:58+00:00Added an answer on June 13, 2026 at 5:00 pm

    Really, you should not use regex for screen scraping. It’s slow and eventually it will break. Instead, use a DOM parser or simply DOMDocument

    <?php 
    //curl bit
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "http://itmindia.edu/index.php?option=com_content&view=article&id=58&Itemid=375&alias=lms");
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    $site = curl_exec($curl);
    curl_close($curl);
    
    
    
    $dom = new DOMDocument();
    @$dom->loadHTML($site);
    
    $ret=array();
    foreach($dom->getElementsByTagName('a') as $links) {
        //Is pdf
        if(substr($links->getAttribute('href'),-3) == 'pdf'){
            //Assign
            $url   = $links->getAttribute('href');
            $title = trim($links->nodeValue);
            $ret[]=array('url'=>'http://itmindia.edu'.$url,
                         'title'=>(empty($title)?basename($url):$title));
        }
    }
    
    print_r($ret);
    /* Result
    Array
    (
        [0] => Array
            (
                [url] => http://itmindia.edu/images/ITM/pdf/ITMU bro june.pdf
                [title] => ITMU Brochure
            )
    
        [1] => Array
            (
                [url] => http://itmindia.edu/images/ITM/pdf/Report_2012_LR.pdf
                [title] => Annual Report to UGC July 2012
            )
    
        [2] => Array
            (
                [url] => http://itmindia.edu/admission2012/PhDwinter/Ph. D. application form 2012-13 for dec 2012 admission.pdf
                [title] => Application Form
            )
    
        [3] => Array
            (
                [url] => http://itmindia.edu/admission2012/PhDwinter/UF_Application_Form.pdf
                [title] => University Fellowship Form
            )
            ...
            ...
    */
    
    //Then to output
    foreach($ret as $v){
        echo '<a href="'.$v['url'].'" target="_blank">'.$v['title'].'</a>';
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use regex in ng-repeat. I have tried the following code but
I want to use regex to replace src html attributes. The HTML is not
I don't know if I can use regex for this, but I want to
I want to use regex to extract the last word from a file path.
If I have a string... abcdefghi and I want to use regex to load
I have a string 1.5(+1.2/-0.5) . I want to use Regex to extract numerical
I want to use regex from a source file named source.html or source.txt :
I want to use Regex.Replace() to change all the patterns like (number)(letter) into (number)(space)(letter).
I want to parse a file and I want to use php and regex
I have a long list like this sb.AppendLine(product.product_id.Length.ToString()) I want to use regex search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.