I am using this code to convert the & to its html entity but it doesn't work. The output is passed to a field in gravity forms.

<a href="/enquiry/?event=<?php $urlst=get_field('fl_name');htmlspecialchars($urlst, ENT_QUOTES);echo $urlst; ?>">Make a request</a>

If I have fl_name= Music & TV Shows then in my gravity forms output i only see Music


The best thing to do here is use the tools that WordPress has provided for you to construct your URLs.

In this solution you're building an array of URL parameters with keys and values, then you're "attaching" these parameters to the array using add_query_arg.

You can reuse this approach for all your URLs, and simply add/adjust your $parameters array as you need it, and the URL.

$parameters = [
    'event' => get_field( 'fl_name' ),

$final_url = add_query_arg( $parameters, site_url( '/enquiry/' ) );

then simply echo out your $final_url wherever you need it:

<a href="<?php echo $final_url; ?>">Make a request</a>

A one-liner version of all of this is:

<a href="<?php echo add_query_arg( [ 'event' => get_field( 'fl_name' ) ], site_url( '/enquiry/' ) ) ;?>">Make a request</a>

Not the answer you're looking for? Browse other questions tagged or ask your own question.