php


Anchor tag setup for given string with php


I have the following strings:
1)search #test
2)search https://example.com/search#test".
3)searchhttps://example.com#test"
I need to convert it to:
first one like
search #test
second one should be simple url -
search https://example.com#test
third one should be remain same
searchhttps://example.com#test"
1st
$pattern = '/search\s(#)+(.+)/';
$string = "search #test";
$string = preg_replace($pattern, 'search https://example.com#\2', $string);
echo $string;
2nd
$pattern = '/search\s(http(s)*(.*))(#)+(.+)/';
$string = "search https://example.com/search#test";
$string = preg_replace($pattern, 'search #\5', $string);
echo $string;
Simply apply the first one, and then the second one to the text you want to process.
$pattern = '/search\s(#)+(.+)/';
$string = "whateveryouwant";
$string = preg_replace($pattern, 'search https://example.com#\2', $string);
$pattern = '/search\s(http(s)*(.*))(#)+(.+)/';
$string = preg_replace($pattern, 'search #\5', $string);
EDIT
2nd case, generic url
$pattern = '/search\s(http(s)*(.*))(#)+(.+)/';
$string = preg_replace($pattern, 'search #\5', $string);
For the first case, no url can be recognized.

Related Links

JQuery table row deletion error
Guzzle encodes body to Json, but I want form data
extract entities in symfony2 controller
How to union all +1 table on this?
Android WebView Cookie issue
Retrieving Combobox selected value php
In PHP, how to check for virus when uploading files? [duplicate]
PHP Google Analytic V3 - Return child pages of pagePath
Get JSON value in PHP using different if conditions
Hide url path in one page only
How to use Resource Controller to show different pages
http header redirect from multiple sources
PHP do not parse array input name
Yii2 Getting user input from a form
add html ouput in joomla email
Stop user from viewing page if condition is not met

Categories

HOME
amazon-web-services
apache-nifi
matrix
keyboard
weblogic12c
long-integer
redmine
key
haproxy
command-prompt
website
adobe
slider
fogbugz
header
impala
heuristics
twitter-oauth
lapack
business-intelligence
squid
temperature
pygobject
android-5.1.1-lollipop
android-contacts
word2vec
nose
scheduled-tasks
amazon-mws
spring-ldap
yii2-basic-app
weex
el
uislider
animated-gif
vuforia
fusetools
web-config-transform
history.js
ccavenue
react-bootstrap-table
php-5.3
bonita
ninject
ibm-connections
unmarshalling
source-insight
reporting
lxml
serversocket
apptentive
restful-architecture
buildforge
subclassing
numerics
code-rally
forms-authentication
identify
cartopy
recovery
imgur
game-center
slideshow
cloudera-sentry
fiware-wirecloud
ipp-protocol
daz3d
adblock
nusoap
extjs4.1
watir-webdriver
sequence-diagram
nslayoutconstraint
dtd
msxml
business-rules
google-shopping-api
deviare
java-2d
nclam
conan
noclassdeffounderror
sharepoint-apps
django-redis
ioctl
webgrind
json-spirit
opencyc
lowercase
wlanapi
angular-amd
actionpack
clarion
mathematical-expressions
android-audiomanager
nhibernate-criteria
fat32
jcheckbox
loginview
boolean-algebra
typesafe-stack
django-sites
lsa
application-server
postgres-xc
spiral
ntlmv2
2d-vector
office-app
java.lang.class
microblogging
rtd
directshow.net
grails-validation
data-retrieval
jquery-effects
prism-2
isapi-redirect

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile