Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your best bet is to manually mark up the news posts in some way, to indicate when a name appears. It's the only way to prevent missed names, or improperly parsed names, and to avoid the huge processing requirement of scanning every news story for every possible name from the database.</p> <p>Maybe something with a twittery-syntax like:</p> <pre><code>@[John Lennon] and @[Paul McCartney] wrote some of the most popular songs in the history of rock music. </code></pre> <p>Then run it through a custom sort of <a href="http://daringfireball.net/projects/markdown/" rel="nofollow noreferrer">markdown</a>-style function when you want to display the news story. It could parse those markers out, find the matching DB record, and generate the link.</p> <p>It'd be more efficient to convert @[] markers to links before inserting the news story in the database, but that couples things more tightly - if a user is deleted or his ID changes, you have a broken link. Storing the @[] also makes editing stories easier.</p> <h3>Update</h3> <p>If you must have the names automagically detected and converted to links, this can be achieved at a pretty severe performance penalty that only grows as you add more names:</p> <pre><code>function linkify_names($news) { $people = query('select people_id, firstname, lastname from people'); $from = $to = array(); foreach ($people as $person) { $name = "$person-&gt;firstname $person-&gt;lastname"; // TODO - escape regex chars in $name? // match [boundary]$name[boundary], case insensitive $from[] = "/(\b)($name)(\b)/i"; // include boundaries in replacement; maintain case of found name $to[] = '$1&lt;a href="/people/' . $person-&gt;people_id .'"&gt;$2&lt;/a&gt;$3'; } return preg_replace($from, $to, $news); } </code></pre> <p>The difference is, instead of looking up only the names marked with @[] tags, you must look up <em>all</em> names, and exhaustively search for each one. You cannot rely on simple regular expressions to find names in the body of the news document.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload