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

  • SEARCH
  • Home
  • 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 8550689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:00:42+00:00 2026-06-11T14:00:42+00:00

I have a url grabber setup and it was working fine. It grabs the

  • 0

I have a url grabber setup and it was working fine. It grabs the url of a doc that is in a response header such as:

<script type='text/javascript' language='JavaScript'>
document.location.href = 'http\x3a\x2f\x2fcms.example.com\x2fd\x2fd\x2fworkspace\x2fSpacesStore\x2f61d96949-b8fb-43f1-adaf-0233368984e0\x2fFinancial\x2520Agility\x2520Report.pdf\x3fguest\x3dtrue'
</script>   

Here is my grabber script.

<?php

set_time_limit(0);
$target_url = $_POST['to'];
$html =file_get_contents($target_url);

$pattern = "/document.location.href = '([^']*)'/";
preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE, 3);

$raw_url = $matches[1][0];
$eval_url = '$url = "'.$raw_url.'";';

eval($eval_url);
echo $url;

We had to add a variable to our doc management system so each doc url needed ?guest=true on the end of the url. When we did this my grabber returned the full url and appends that to the filename. So I tried to have it grab just the url until it hit /guest=true. With this code:

<?php

set_time_limit(0);

$target_url = $_POST['to'];
$html =file_get_contents($target_url);

$pattern = "/document.location.href = '([^']*)\x3fguest\x3dtrue'/";

preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE, 3);

$raw_url = $matches[1][0];
$eval_url = '$url = "'.$raw_url.'";';

eval($eval_url);
echo $url;

Why isn’t it returning the url up until the ?guest=true part? aka why doesn’t this work? and what’s the fix?

  • 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-11T14:00:43+00:00Added an answer on June 11, 2026 at 2:00 pm

    This is the solution. You’ll get the match directly, not in group.

    set_time_limit(0);
    
    $target_url = $_POST['to'];
    $html = file_get_contents($target_url);
    
    $pattern = '/(?<=document\.location\.href = \').*?(?=\\\\x3fguest\\\\x3dtrue)/';
    
    preg_match($pattern, $html, $matches))
    
    $raw_url = $matches[0];
    $eval_url = '$url = "'.$raw_url.'";';
    
    eval($eval_url);
    echo $url;
    

    You can check out the results here.

    The problem with your regex was in the fact that you did not escape certain characters in the string (. and \) that you wanted to catch literary. Furthermore, you do not need to use PREG_OFFSET_CAPTURE and offset of 3. I guess you copied these values from the example on this page.

    Here’s an explanation of the regex pattern:

    # (?<=document\.location\.href = ').*?(?=\\x3fguest\\x3dtrue)
    # 
    # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) «(?<=document\.location\.href = ')»
    #    Match the characters “document” literally «document»
    #    Match the character “.” literally «\.»
    #    Match the characters “location” literally «location»
    #    Match the character “.” literally «\.»
    #    Match the characters “href = '” literally «href = '»
    # Match any single character that is not a line break character «.*?»
    #    Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
    # Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=\\x3fguest\\x3dtrue')»
    #    Match the character “\” literally «\\»
    #    Match the characters “x3fguest” literally «x3fguest»
    #    Match the character “\” literally «\\»
    #    Match the characters “x3dtrue” literally «x3dtrue»
    

    This answer has been edited to reflect updates to the question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JQuery function that grabs the URL path and adds it as
I have url http://translate.google.ru/translate_a/t?client=x&text=ввійти вийти&sl=ua&tl=en If you will go through this link in response
I have url http://translate.google.ru/translate_a/t?client=x&text=enter text&sl=en&tl=pl If you will go through this link in response
I have a simple regular expression that matches some URL and it works fine
I have a url of a type where query string is like this... ?
I have url that looks like this... http://www.example.com/accounts/?token=111978178853984|683b8096732be7fd725d3332-557626087|m9lSbmoYhZ6Yut4OC3smY1fRf1E. from the token 111978178853984|683b8096732be7fd725d3332- 557625434 |m9lSbmoYhZ6Yut4OC3smY1fRf1E
Imagine that I have url http://www.google.com/subdomain/blah-blah.../.. /.. So I want to extract 4 things
I have a site that have URL similar to this: /mysite/admin/controller/action/id /mysite/search/controller/action/id /mysite/user/controller/action/id I
So I have a form that has 4 inputs, 2 text, 2 hidden. I've
I have URL like: http://example.com#something , how do I remove #something , without causing

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.