Convert the_permalink() function output into string

Use get_permalink() function which returns a value instead of printing it.

Example –

$permalink = get_permalink($id); //$id if using outside loop