magento
asked on
Easy script
Hi ,
I have a few lines of text in a flat file which i need to convert something like below.
Input
Bari Durrës Bari
Brindisi Vlore
Output
<a title="Bari Durrës Bari" href="http://www.test.fr/bari-durres-bari/">Bari Durrës Bari</a>
<a title="Brindisi Vlore" href="http://www.test.fr/Brindisi-Vlore/">Brindisi Vlore</a>
Thanks,
Magento
I have a few lines of text in a flat file which i need to convert something like below.
Input
Bari Durrës Bari
Brindisi Vlore
Output
<a title="Bari Durrës Bari" href="http://www.test.fr/bari-durres-bari/">Bari Durrës Bari</a>
<a title="Brindisi Vlore" href="http://www.test.fr/Brindisi-Vlore/">Brindisi Vlore</a>
Thanks,
Magento
ASKER
Hi ,
In the second part of the $line it should add - instead of space.
Thanks
In the second part of the $line it should add - instead of space.
Thanks
Ooops, sorry:
$lines = file('textfile.txt');
foreach ($lines as $line) {
$urlline = str_replace(' ', '-', $line);
echo "<a title=\"$line\" href=\"http://www.test.fr/$urlline\">$line</a><br />";
}
Why is bari-durres-bari lowecased but Brindisi-Vlore capitalized?
ASKER
Ozo ,
Thanks for checking in .
Yes, it should be in lowercase only as my 1st sample in the output .
Sorry for pasting it wrong.
Thanks
Thanks for checking in .
Yes, it should be in lowercase only as my 1st sample in the output .
Sorry for pasting it wrong.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
perl -Mutf8 -Mcharnames=:full -lpe '$s=$_;utf8::decode$_;s/\s /-/g;s{([^ \0-\177])} {charnames ::string_v ianame(((c harnames:: viacode ord $1)=~/(.*?)( WITH )?/)[0])}ge;$_=qq{<a title="$s" href="http://www.test.fr/\L$_\E/">$_</a>}'
ASKER
Thanks MarqusG, it works well.
Ozo , You are genius in perl :)
I always really wonder what actually is the code .
But as a learning part , can you provide a simple perl script instead one liner with comments?
Ozo , You are genius in perl :)
I always really wonder what actually is the code .
But as a learning part , can you provide a simple perl script instead one liner with comments?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks everyone for your kind help.
I will close this question sooner.
I will close this question sooner.
Open in new window