473,785 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string http:// conwert to <a href=''>host</a>

hi

in form TEXTAREA i have text like:

bla bla http://www.google.com/bla/bla/bla text text text text
now how to make from this text like:

bla bla ['http://www.google.com'] text text text text
['']-> url to http://www.google.com/bla/bla/bla
I wrote this script:
Were error is?
ps. sorry , my english is not good.:)
<?
function string_url($tex t) {

$arr=explode("\ n", $text);
$j=0;
foreach( $arr as $val)
{

if( strlen($val) > 1 )
{
$arr2=explode(" ", $val);
$i=0;
foreach( $arr2 as $val2)
{

$findme = 'http';
$pos = strpos($val2, $findme);
if ($pos === false)
{

$arr2[$i] = $val2;
}

else {

$val2=parse_url ($val2);
$host=$val2['host'];
$path=$val2['path'];
$scheme=$val2['scheme'];
$tekst="<a HREF=\"$scheme://";
$tekst.=$host;
$tekst.=$path;
$tekst.=">$host </a>";
$arr2[$i]=$tekst;
}

$i++;
}//koniec 2 forech (slowa)
$slowa=implode( " ", $arr2);
$arr[$j] = $slowa;

}
else
{
$arr[$j] = $val;
}

$j++;
}//koniec 1 forech
$text_nowy= implode("\n", $arr);
return $text_nowy;
}


if ( $tresc) {

echo string_url($tre sc);
} else {
print "<FORM METHOD=POST > </B><B>title:</B><BR>";
print "<TEXTAREA NAME=tresc ROWS=30 COLS=60
$tresc</TEXTAREA><BR>";

print "<br><INPUT TYPE=\"submit\" VALUE=\"add!\"> <br><br>";
print "</FORM>";
}
?>

Oct 14 '05 #1
5 2092
Am Fri, 14 Oct 2005 12:23:24 -0700 schrieb specjal:
hi

in form TEXTAREA i have text like:

bla bla http://www.google.com/bla/bla/bla text text text text
now how to make from this text like:

bla bla ['http://www.google.com'] text text text text
['']-> url to http://www.google.com/bla/bla/bla
I wrote this script:
Were error is?
ps. sorry , my english is not good.:)
<?
function string_url($tex t) {

$arr=explode("\ n", $text);
$j=0;
foreach( $arr as $val)
{

if( strlen($val) > 1 )
{
$arr2=explode(" ", $val);
$i=0;
foreach( $arr2 as $val2)
{

$findme = 'http';
$pos = strpos($val2, $findme);
if ($pos === false)
{

$arr2[$i] = $val2;
}

else {

$val2=parse_url ($val2);
$host=$val2['host'];
$path=$val2['path'];
$scheme=$val2['scheme'];
$tekst="<a HREF=\"$scheme://";
$tekst.=$host;
$tekst.=$path;
$tekst.=">$host </a>";
$arr2[$i]=$tekst;
}

$i++;
}//koniec 2 forech (slowa)
$slowa=implode( " ", $arr2);
$arr[$j] = $slowa;

}
else
{
$arr[$j] = $val;
}

$j++;
}//koniec 1 forech
$text_nowy= implode("\n", $arr);
return $text_nowy;
}


if ( $tresc) {

echo string_url($tre sc);
} else {
print "<FORM METHOD=POST > </B><B>title:</B><BR>";
print "<TEXTAREA NAME=tresc ROWS=30 COLS=60
$tresc</TEXTAREA><BR>";

print "<br><INPUT TYPE=\"submit\" VALUE=\"add!\"> <br><br>";
print "</FORM>";
}
?>


$tresc = preg_replace('/(http)(s?)(://)([^ ]+)/', '<a
href="$1$2$3$4" >$1$2$3$4</a>', $tresc);

--
-------------------------------------------------------
Try this: SCA the Smart Class Archive for PHP
http://www.project-sca.org
-------------------------------------------------------

Oct 14 '05 #2
Warning: Unknown modifier '/'
what is wrong?

$tresc = preg_replace('/(http)(s?)(://)([^ ]+)/', '<a
href="$1$2$3$4" >$1$2$3$4</a>', tresc);

Oct 15 '05 #3
specjal wrote:
Warning: Unknown modifier '/'
what is wrong?

$tresc = preg_replace('/(http)(s?)(://)([^ ]+)/', '<a
href="$1$2$3$4" >$1$2$3$4</a>', tresc);


The slashes are used as modifiers to mark the beginning and the end of the
pattern, but they are also used in the pattern itself.

You can fix this by escaping the slashes in the pattern:

$tresc = preg_replace('/(http)(s?)(:\/\/)([^ ]+)/', '<a
href="$1$2$3$4" >$1$2$3$4</a>', tresc);

Or by using another modifier:

$tresc = preg_replace('# (http)(s?)(://)([^ ]+)#', '<a
href="$1$2$3$4" >$1$2$3$4</a>', tresc);
JW

Oct 15 '05 #4
Janwillem Borleffs wrote:
specjal wrote:
Warning: Unknown modifier '/'

$tresc = preg_replace('/(http)(s?)(://)([^ ]+)/', '<a
href="$1$2$3$4" >$1$2$3$4</a>', tresc);


The slashes are used as modifiers to mark the beginning and the end of the
pattern, but they are also used in the pattern itself.


No -- the slashes are used as *delimiters*. The *modifiers* are any extra
characters that occur after the end delimiter. For example:

/foo/i

will match 'foo' case-insensitively. In this example, the 'i' is a
modifier -- it modifies the behaviour of the regular expression to make it
case-insensitive.

Specjal's warning is caused by the third slash. PHP sees the second slash
as the end delimiter, which makes any trailing characters modifiers.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Oct 15 '05 #5
Toby Inkster wrote:
No -- the slashes are used as *delimiters*. The *modifiers* are any
extra characters that occur after the end delimiter.


Yeah, you're right.
JW

Oct 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
10095
by: Nick Keighley | last post by:
I'm probably missing something rather obvious, but is there a known problem with getting a Python based socket program to communicate with a C based socket program? A simple echo server written in Python (the example from Python in a Nutshell actually) will happily talk to a Python based client. If a C based client is substitued the connection is refused (or so the C client reports). The C client will talk to a C server. --
0
4977
by: Matt | last post by:
I'm trying to get the HTML data off of a webpage. Let's say for the sake of argument it's the python homepage. I've googled around and found some examples that people said worked. Here's what I've cobbled together: #getHTML.py ############################################ import urllib import urllib2 proxy_info = {'user':'us3r',
0
1206
by: news.microsoft.com | last post by:
hello, all. I am trying to convert a struct from VB to c# in order to use an old DLL. Here is the definition in VB Public Type CHost Host As String * 60 Port As String * 5 Info As String * 120 'Inof returned from host Timeout As String * 10 End Type
0
1120
by: juannorton | last post by:
Hi got db2 v8.2 on win 2003 I configurated the smtp server so i can receive notifications from the task center, but my smtp server refuse the email adddress from the sender. If any way to change the sender's email? Or anyone knows a public server that accepts those kind of emails? Thanks
8
1640
by: Mark | last post by:
We have a multi-line textbox that users copy and paste email text into. The pasted text frequently will contain a tag like <blah@aol.com> or similar. I believe .NET is protecting itself from code injection by throwing a global error when this occurs. The exception message is pasted below. We will NOT be able to train our users to eliminate all <> tags. What's the best way to deal with this issue? Thanks in advance.
10
2430
by: Dia | last post by:
At the company I work job applicants are required to do a little test. The human resource manager recently had a candidate who claimed one of the questions was ambiguous. Dependent upon the version of DB2 one or the other answer of a multiple choice question could be right, the candidate said. The HRM asked me to look into the matter, but since I am no expert in the workings of DB2 I submit the question to you hoping any of you can
5
3139
by: KL | last post by:
I have a problem trying to write to a binary file that I want to name after a particular name from a set. My code for the function follows, please excuse the horrible mistakes you may see, I am a student, and trying my best. void retrieveImage(set<string>finalset, string hostname, string filename){ set<string>::iterator i; string img, filetoget; char test; for (i = finalset.begin();i != finalset.end();i++){
8
1364
by: Benjamin Bécar | last post by:
Hello everyone. I have to find a correct architecture to achieve this XML <=Text conversion platform. The platform (based on Win2003Server) will have to deal with 21 million XML files and 16 million text files a day. The average file size is 1,1 Kb, but they are received by the platform in the form of big archives (7000 files per archive, app. 7.7Mb). After some investigation on the Internet, I have decided (95% sure) to use SAX as...
2
2271
dlite922
by: dlite922 | last post by:
Hello Hello! I'm trying to connect to a host that accepts UDP on a port I setup and tested from a command line too called udp_write. However a PHP fsocketopen() call doesn't work nor does it give an error. stripped down code + fake data: $fp = fsockopen("udp://999.999.999.999",9999,$errNo,$errMsg) or die("$errNo : $errMsg"); $test = fwrite($fp, "Logging Test");
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.