3

code:

<?php
    include('conn.php');
    $student_id = $_SESSION['student_id'];
    $college_name = $_GET['college_name'];
    $college_name22 = explode('(', $college_name);
    if(preg_match('#\((.*?)\)#', $college_name, $match))
    {
        $match[1] = lcfirst($match[1]);
    }
    else
    {
        $match[1] = 'All';
    }

?>

If url having string like

cstest/view.php?college_name=Agra%20Public%20Institute%20of%20Technology%20&%20Computer%20Education,%20Artoni%20(Pharmacy)

and I want to explode the following string i.e.

Agra%20Public%20Institute%20of%20Technology%20&%20Computer%20Education,%20Artoni%20(Pharmacy)

when I echo $college_name it display only (Agra Public Institute of Technology) not full name i.e (Agra Public Institute of Technology & Computer Education, Artoni) and $match[1] contain (pharmacy) which is not showing when I print $match[1] it show 'All'. So, how can I fix this problem ?

Thank You

1
  • var_dump($_GET) looks like what? For starters, it's not going to have URL encoded strings in it. And if you're accessing a URL with , and ( in it, your browser has problems, they would also be encoded as %2C and %28. Commented Apr 20, 2017 at 5:34

1 Answer 1

2

The & has a special meaning in URL. the value of $_GET['college_name'] is exactly "Agra%20Public%20Institute%20of%20Technology%20". The & marks the start of a new parameter.

If the ampersand is properly escaped as %26 you will have a much easier time.

You could try inserting a var_dump($_GET) and see what the data is that you are actually working with.

Sign up to request clarification or add additional context in comments.

2 Comments

I am using var_dump like $college_name = var_dump($_GET['college_name']); and it give the following result like string(36) "Agra Public Institute of Technology
var_dump the whole array, $_GET. See what else you have in there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.