Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to explode a url string?

Tags:

php

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

like image 204
kevin Avatar asked Feb 04 '26 17:02

kevin


1 Answers

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.

like image 160
Octopus Avatar answered Feb 12 '26 17:02

Octopus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!