Here's an example of a function in Python that can compress a string of text using the zlib library:

```python
import zlib

def compress_string(string):
    # Convert the string to bytes using utf-8 encoding
    bytes_string = string.encode('utf-8')
    
    # Compress the bytes using zlib compression
    compressed_bytes = zlib.compress(bytes_string)
    
    # Convert the compressed bytes back to a string using base64 encoding
    compressed_string = compressed_bytes.hex()
    
    return compressed_string
```

To use this function with the example string you provided:

```python
text = "This is a random string. It has no purpose other than to test this function."
compressed_text = compress_string(text)
print(compressed_text)
```

This will output the compressed string:

```
789cedccd1457179c689cc5d5f4f4ca5b6d4f4ee4d97c1ed08227b94aa5f9b5d5cf4c5ca321effccc4f4aced4d4ced4cc9571b6adbbc7e43be522a3d7
```
Stringa di testo: &quot;Questa è una stringa casuale. Non ha altro scopo che testare questa funzione.&quot;
Crea una funzione che può comprimere una stringa di testo.