Paragraph tagging

I use PHP and I am looking to create links in my text for other sections of the site, for example:

I fell into the media industry aged 30, when David Mansfield, now on the board of
Ingenious Media, gave me my first break at Thames TV. From there, I worked at the
(now-defunct) Sunday Correspondent and IPC, before joining TDI, which became Viacom
and then CBS Outdoor. After 12 years in outdoor, I spent a year out doing overseas
outdoor consultancy work in Russia, Dubai and Spain, as well as launching the media 
CRM business, Media By Permission. I have been lucky enough to work across a range of 
media, but outdoor would definitely be my specialist subject on 'Mastermind'.

I would like to link Ingenious MediaThe page is all about Ingenious Media, but I would also like to link all references Mediato a media page.

Obviously I don’t want to bind the word MediainsideIngenious Media

How can I do this without double linking to some words?

Thanks in advance

+3
source share
4 answers

Step 1. Create a new array containing the names of the objects that you want to "mark", and order the smallest entity name for the longest object name.

2. (, ## . rand(100, 999) * rand(100, 999)). , , .

3. , , - .

4. , .

+1

, . - :

  • , ( a, , , , , eding, )
  • ,
0

Maybe if you use greedy regular expressions to match phase as much as possible. look at those links http://www.exampledepot.com/egs/java.util.regex/Greedy.html and http://www.regular-expressions.info/repeat.html

0
source
$string = '...your string from above....';

// Here we replace only "Media" when there is no "Ingenious " in front of it.
$string = preg_replace('#(?<!Ingenious )Media#', '<a href="media.html">Media</a>', $string);

// Here don't need to use a regex...
$string = str_replace('Ingenious Media', '<a href="ingenious_media.html">Ingenious Media</a>', $string);
echo $string;

I am sure that there is a better regular expression, because there is always;) but this is how it works, it just tested it :)

0
source

Source: https://habr.com/ru/post/1751531/


All Articles