Welcome Guest, Not a member yet? Register   Sign In
pre_replace not sure what the correct expression is
#11

[eluser]sophistry[/eluser]
this might help. i renamed the word_censor function (as it was posted in the linked thread) to regex_mill()

i believe that this demonstrates almost perfectly what you are looking for:
Code:
$s = 'this is a <a href="string">string</a> with text/texts and HTML anchor and img tags (img tag here: <img src="">) mixed in. this is a string without a tag.';
$lookfor = array('(\s)(string)(\s)', 'texts?', 'HTML anchor', '[^<](img)');
$replacements = array('$2<a href="tags/$3">$3</a>$4','<a href="tags/$1">$1</a>','<a href="tags/$1">$1</a>','<a href="tags/$2">$2</a>');

$out = regex_mill($s, $lookfor, $replacements, 'i');
print_r(htmlentities($out));

to understand and use this regex_mill you are going to have to learn some regex to "tune" what the patterns find and what they are replaced with, but this should get you going with the basics.

happy birthday!
#12

[eluser]bugboy[/eluser]
Thank you so much,

I'll give it a go and see what i'll come upi
#13

[eluser]bugboy[/eluser]
your a star this is working great so far.
#14

[eluser]bugboy[/eluser]
Hi I've got it working with single words but when i come across a multiple words it stops working.

I've been reading that regex ref site you linked me too which great.

i think it regex to stop a string with multiple words appearing in a link would be

Code:
[^<](wordone wordtwo)

But it stops working completely.
#15

[eluser]sophistry[/eluser]
it depends which part of the "link" you are referring to. the href attribute or the display text that shows in between the open and close "a" tags?

which one of these:
Code:
<a href="this/is/a/path/and/shouldnothavespaces">display text with spaces</a>

if it is the display text, you just need to turn your less-than into a greater-than:

Code:
[^>](wordone wordtwo)

note: this assumes no space between the greater-than sign and the string "wordone".

cheers.
#16

[eluser]bugboy[/eluser]
Once again your a star.

Cheers for that




Theme © iAndrew 2016 - Forum software by © MyBB