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 6476177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:47:34+00:00 2026-05-25T06:47:34+00:00

I am passing a string through a URL to another page whenever a link

  • 0

I am passing a string through a URL to another page whenever a link is clicked.

The original a tag and its href are created via a PHP while loop as follows:

<a href=".($row['secondary'] == 'true' ? "secondary_imgs.php?imgId=".$row['imgId']."
    &imgTitle=".$row['imgTitle']."" : "new_arrivals_img/".$row['imgURL']."").">

Note: The a tag does contain other attributes but I removed them for simplicity.

The href is then appended, with the current window dimensions, using the following jQuery function:

$("a[href^='secondary_imgs.php']").click(function(){
    var pageWidth = $(window).width();
    var pageHeight = $(window).height();
    var url = $(this).attr('href');
    var idx = url.indexOf('&pageWidth=');
    if (idx != -1) {
        url = url.substr(0, idx);
    }
    url += '&pageWidth=' + pageWidth + '&pageHeight=' + pageHeight;
    $(this).attr('href', url);
});

My question is, what method(s) of encoding the URL should I use in this case, seeing as it will need to be done with first PHP, then jQuery/JavaScript, and finally decoded via PHP?
Or will it need to be done in both PHP and jQuery/JavaScript? The original PHP $row['imgTitle'] will always have at least spaces in it, and so I know it needs to be done then for sure. But seeing as the appended values will always be a variable equalling a number, does that need to be encoded as well?

I know there are several methods of encoding/decoding URLs in each coding language, and my knowledge isn’t adequate enough to make the choice.

If someone could also provide an example of how I would perform each step, it would be much appreciated.

  • 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-05-25T06:47:34+00:00Added an answer on May 25, 2026 at 6:47 am

    You should use urlencode() in PHP to encode URI components.

    The equivalent function in javascript is encodeURIComponent().

    PHP will decode parameters encoded like this automatically.

    So, in you PHP:

    '<a href="..&imgTitle='.urlencode($row['imgTitle'])
    

    And equivalently, in your javascript:

    '&someparam=' + encodeURIComponent(someValue)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am passing a string into a hidden field on the page and then
I'm passing query string parameter to .aspx page with 'Ñ' character in value. But
Is there a benefit to passing a string in your url patters vs a
I'm passing a URL variable to a PHP page that is outputting an XML
On my site right now, I'm passing in data through a query string to
One of the things I find myself doing often is passing string literals as
I've got a std::map: std::map<std::string, std::string> I'm passing string literal to find method. Obviously,
I'm used to passing around string like this in my C++ applications: void foo(const
Curently I'm passing my const string values up from my C++ into my C#
After reading about the problem of passing empty std::string objects between DLLs and EXEs,

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.