---
[Gratis] Tweetize class
---
2 simpele functions, maar wel leuk voor je eerste class..
Bedankt.
Bedankt.
Ziet er leuk uit, maar sowieso de preg_replace moet anders. Met iets betere research kun je zulk soort foutjes voorkomen
De verbeterde:
De verbeterde:[COLOR= #0000BB]<?php
$username[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]/@([A-Za-z0-9_]{1,15})/[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$hashtag[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]/#([A-Za-z0-9_]+)/[/COLOR][COLOR= #007700];[/COLOR]
?> Xjessex schreef:Bedankt.2 simpele functions, maar wel leuk voor je eerste class..
Bedankt.
Jenner schreef:Veranderd, bedankt.Ziet er leuk uit, maar sowieso de preg_replace moet anders. Met iets betere research kun je zulk soort foutjes voorkomenDe verbeterde:
[COLOR= #0000BB]<?php $username[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]/@([A-Za-z0-9_]{1,15})/[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$hashtag[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]/#([A-Za-z0-9_]+)/[/COLOR][COLOR= #007700];[/COLOR] ?>
Nette eerste class hoor, alleen zou ik (iig voor functies) camelCase gebruiken
Als je tweets ophaalt voor je website kan je misschien toch beter gewoon deze functie gebruiken.
function makeLinksClickable($text)
{
$text = preg_replace("#(^|[n ])([w]+?://[w]+[^ "nrt< ]*)#", "1<a href="2" target="_blank">2</a>", $text);
$text = preg_replace("#(^|[n ])((www|ftp).[^ "tnr< ]*)#", "1<a href="http://2" target="_blank">2</a>", $text);
$text = preg_replace("/@(w+)/", "<a href="http://www.twitter.com/1" target="_blank">@1</a>", $text);
$text = preg_replace("/#(w+)/", "<a href="http://search.twitter.com/search?q=1" target="_blank">#1</a>", $text);
return $text;
} Mag ik een klein vraagje stellen, ik weet niet zoveel af van twitter dus kan deze vraag dom klinken:
Wat doet deze Twitter class? Wat ben je ermee? Wat voert hij uit??
Wat doet deze Twitter class? Wat ben je ermee? Wat voert hij uit??
Sanderc schreef:Lezen is een kunst he?Mag ik een klein vraagje stellen, ik weet niet zoveel af van twitter dus kan deze vraag dom klinken:
Wat doet deze Twitter class? Wat ben je ermee? Wat voert hij uit??
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/**
* Functie: Zet # en @ om naar een link naar twitter
**/[/COLOR]
?> Aarclay schreef:Waarschijnlijk weet hij niet wat er met # en @ word bedoeld..Wat doet deze Twitter class? Wat ben je ermee? Wat voert hij uit??Eerdere citaten tonen
Sanderc schreef:Mag ik een klein vraagje stellen, ik weet niet zoveel af van twitter dus kan deze vraag dom klinken:
Lezen is een kunst he?[COLOR= #0000BB]<?php[/COLOR] [COLOR= #FF8000]/** * Functie: Zet # en @ om naar een link naar twitter **/[/COLOR] ?>
Maar goed

Nicknl schreef:Dan kan hij zich niet afvragen, want dan heeft hij het al gelezenWaarschijnlijk weet hij niet wat er met # en @ word bedoeld..Eerdere citaten tonen
Aarclay schreef:Wat doet deze Twitter class? Wat ben je ermee? Wat voert hij uit??Eerdere citaten tonen
Sanderc schreef:Mag ik een klein vraagje stellen, ik weet niet zoveel af van twitter dus kan deze vraag dom klinken:
Lezen is een kunst he?[COLOR= #0000BB]<?php[/COLOR] [COLOR= #FF8000]/** * Functie: Zet # en @ om naar een link naar twitter **/[/COLOR] ?>
Maar goed
Kyron schreef:Veel mensen gebruiken ook gewoon underscores. Past PHP ook gewoon toe. Nog een paar tips voor de volgende keer. Kun je beter deze implementatie gebruiken:Nette eerste class hoor, alleen zou ik (iig voor functies) camelCase gebruiken
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]//Static function is handiger in dit geval.[/COLOR]
[COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] Twitter[COLOR= #007700]::[/COLOR]change[COLOR= #007700]([/COLOR][COLOR= #0000BB]$oldstring[/COLOR][COLOR= #007700]);[/COLOR]
?> En waarom zou static beter zijn? Beargumentatie wordt wel op prijs gesteld
.
.Jenner schreef:Quote:Veel mensen gebruiken ook gewoon underscores. Past PHP ook gewoon toe. Nog een paar tips voor de volgende keer. Kun je beter deze implementatie gebruiken:Eerdere citaten tonen
Kyron schreef:Nette eerste class hoor, alleen zou ik (iig voor functies) camelCase gebruiken[COLOR= #0000BB]<?php[/COLOR] [COLOR= #FF8000]//Static function is handiger in dit geval.[/COLOR] [COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] Twitter[COLOR= #007700]::[/COLOR]change[COLOR= #007700]([/COLOR][COLOR= #0000BB]$oldstring[/COLOR][COLOR= #007700]);[/COLOR] ?>
Fatal error: Using $this when not in object context in /home/****/domains/********/public_html/spel/test_bestanden/class.php on line 16
Dat krijg ik er dan uit?
misschien er even bijzetten dat die moet worden included.
De (naar mijn inzien) verbeterde class:
Hoe te gebruiken?
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/**
* Maker: GameDealer
* Datum: 11-04-2012
* Naam: Twitter script
* Functie: Zet # en @ om naar een link naar twitter
**/[/COLOR]
[URL="http://www.php.net/class"]class[/URL] Twitter
[COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$text[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]// De tekst die veranderd moet worden updaten[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] change[COLOR= #007700]([/COLOR][COLOR= #0000BB]$set_text[/COLOR][COLOR= #007700])
{[/COLOR]
[COLOR= #FF8000]//Standaard tekst neerzetten[/COLOR]
[COLOR= #0000BB]$text[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$set_text[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]//Standaard tekst naar namen veranderen[/COLOR]
[COLOR= #0000BB]$text[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]:[/COLOR]SMILEYYYYYYYYYYYBEGIN[COLOR= #007700]:[/COLOR]set_names[COLOR= #007700]([/COLOR][COLOR= #0000BB]$text[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #FF8000]//Standaard tekst naar hashtags veranderen[/COLOR]
[COLOR= #0000BB]$text[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]:[/COLOR]SMILEYYYYYYYYYYYBEGIN[COLOR= #007700]:[/COLOR]set_hashtag[COLOR= #007700]([/COLOR][COLOR= #0000BB]$text[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #FF8000]//Tekst terugsturen[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$text[/COLOR][COLOR= #007700];
}[/COLOR]
[COLOR= #FF8000]//Functie voor namen omzetten in links[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] set_names[COLOR= #007700]([/COLOR][COLOR= #0000BB]$text[/COLOR][COLOR= #007700])
{[/COLOR]
[COLOR= #0000BB]$change[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]/[@]+([A-Za-z0-9-_]+)/[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$replacement[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]<a href="http://twitter.com/$1" target="_blank">@$1</a>[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$text[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$change[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$replacement[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$text[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$text[/COLOR][COLOR= #007700];
}[/COLOR]
[COLOR= #FF8000]//Functie voor hashtags omzetten in links naar zoekfunctie[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] set_hashtag[COLOR= #007700]([/COLOR][COLOR= #0000BB]$text[/COLOR][COLOR= #007700])
{[/COLOR]
[COLOR= #0000BB]$change[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]/[#]+([A-Za-z0-9-_]+)/[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$replacement[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]<a href="http://twitter.com/#!/search/%23$1" target="_blank">#$1</a>[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$text[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$change[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$replacement[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$text[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$text[/COLOR][COLOR= #007700];
}
}[/COLOR]
?> Hoe te gebruiken?
[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]#hier #je #hashtags #en @one2xs[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$twitter[/COLOR] [COLOR= #007700]=[/COLOR] Twitter[COLOR= #007700]::[/COLOR]change[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #0000BB]$twitter[/COLOR][COLOR= #007700];[/COLOR]
?>