These are chat archives for collectiveaccess/support

20th
Dec 2017
ca-ubos
@ca-ubos
Dec 20 2017 10:02

Hi! I need some help using php preg_replace with attributes in pawtucket2. For instance I’d like to change the LCSH ID to a URL.

Calling

<unit relativeTo="ca_objects.lcsh_terms.id" delimiter="<li>"><a href="^ca_objects.lcsh_terms.id">^ca_objects.lcsh_terms.text</a></unit>

gets me info:lc/authorities/names/n86705923. Using preg_replace I wish I could change this to http://id.loc.gov/authorities/names/n86705923. The following code however does not work:

<?php
    $str = '^ca_objects.lcsh_terms.id';
    $re = '/info:lc/';
    $subst = 'http://id.loc.gov';
    $result = preg_replace($re, $subst, "$str");
    echo "The result of the substitution is ".$result;
?>

The output is:

The result of the substitution is info:lc/authorities/names/n86705923

What am I missing here? It is like the $str is not handled as a string…

sshipley64
@sshipley64
Dec 20 2017 18:39
I'm having an issue that often but not always, when I try to save search tools, metadata elements in the manage menu or create entities from the quick add , the user is logged out, and all the information is gone when logged back in. This can happen several times in a row.
Mike Benowitz
@mwbenowitz
Dec 20 2017 18:52
@ca-ubos your third argument to preg_replace doesn't need to be in quotes. You could also use str_replace if you'll always be replacing "info:lc". It takes the same arguements: str_replace('info:lc', 'http://id.loc.gov', $str)