/    Sign up×
Community /Pin to ProfileBookmark

i found this script to unlink links. What happens here is that all links dissapear and become $word:

[code=php]reg_replace(“/<a href=.*>(.*)</a>/”, $word, $string);[/code]

But i don’t want every link to change into $word I want only links that have $word in them get unlinked. So i thought of something like this:

[code=php]reg_replace(“/<a href=$word>($word)</a>/”, $word, $string);[/code]

this doesn’t work how can I fix this??

This is the full script maybe it helps a external text file is imported and the scripts makes links out of all words in de the text automatically.

[code=php]
<?php
//start sessie
session_start();
header(“Cache-control: private”); // IE6 Fix

//Twee sessie arrays aanmaken
session_register(‘text’);
session_register(‘number’);

//Aantal bezoeken tellen
$_SESSION[‘number’] = $_SESSION[‘number’]+1;

//Alleen in het begin text oproepen
if($_SESSION[‘number’] == 1){
//Zeggen welke text je wilt doen
$text = file(“text.txt”);
//Text op splitsen in apparte woorden om er links van te maken
$split = explode (” “, $text[0]);
//Aantal woorden tellen
$count = count($split);
//For loop om de hele text weer in elkaar te zetten met alle links
for($i = 0; $i <= $count; $i++){
$_SESSION[‘text’] .= “<a href=”.$PHP_SELF.”?word=”.$split[$i].”>”.$split[$i].”</a> “;
//Text weergeven als text helemaal gemaakt is
if ($i == $count){
echo $_SESSION[‘text’];
}
}
}
/*Wanneer we de begin text hebben kunnen we hem de tweede keer
dat we de pagina bezoeken gaan vergaten*/
else {
$_SESSION[‘text’] = preg_replace( “/<a href=.*>(.*)</a>/”, ‘<span style=”color:#000000;font-weight:normal;”>’. $word.'</span>’, $_SESSION[‘text’] );
echo $_SESSION[‘text’];
}

?>[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@JonaFeb 20.2005 — [font=trebuchet ms]Try...[/font]

<i>
</i>preg_replace("/&lt;a href=('|")?$word('|")?&gt;(.*?)&lt;/a&gt;/i", $word, $string);
Copy linkTweet thisAlerts:
@zebdaagauthorFeb 20.2005 — no doesn't work?? I really don't understand anything of the regural expression.

managed to get this:
[code=php]
preg_replace( "/<a href=.*>($word)</a>/", '<span style="color:#000000;font-weight:normal;">'. $word.'</span>', $_SESSION['text'] )
[/code]
Copy linkTweet thisAlerts:
@zebdaagauthorFeb 20.2005 — yahoo got it working now thanks for you help here is the link:

[URL=http://www.jeugdwerkrozenoord.nl/Schaak/sessie_3.php]link[/URL]

and the code:
[code=php]
<?php
//start sessie
session_start();
header("Cache-control: private"); // IE6 Fix

//Twee sessie arrays aanmaken
session_register('text');
session_register('number');

//Aantal bezoeken tellen
$_SESSION['number'] = $_SESSION['number']+1;


//Alleen in het begin text oproepen
if($_SESSION['number'] == 1){
//Zeggen welke text je wilt doen
$text = file("text.txt");
//Text op splitsen in apparte woorden om er links van te maken
$split = explode (" ", $text[0]);
//Aantal woorden tellen
$count = count($split);
//For loop om de hele text weer in elkaar te zetten met alle links
for($i = 0; $i <= $count; $i++){
$_SESSION['text'] .= "<a href=".$PHP_SELF."?word=".$split[$i].">".$split[$i]."</a> ";
//Text weergeven als text helemaal gemaakt is
if ($i == $count){
echo $_SESSION['text'];
}
}
}
/*Wanneer we de begin text hebben kunnen we hem de tweede keer
dat we de pagina bezoeken gaan vergaten*/
else {

$_SESSION['text'] = preg_replace( "/>$word</", '><span style="color:#000000;font-weight:normal;">'. $word.'</span><', $_SESSION['text'] );
echo $_SESSION['text'];
}

?>[/code]
×

Success!

Help @zebdaag spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...